将关闭按钮添加到UIModalPresentationPageSheet角 [英] Add close button to UIModalPresentationPageSheet corner

查看:83
本文介绍了将关闭按钮添加到UIModalPresentationPageSheet角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在UIModalPresentationPageSheet的角落添加按钮?我的意思是,我想将类似Apple的(x)按钮放在页面表格的角落,但是将其添加到父视图会使它显示在页面表格的后面(并且也无法点击)并将其添加到页面表格会隐藏其中的一部分,因为它不在视图区域内.

Is there a way to add a button at the corner of an UIModalPresentationPageSheet? I mean, I want to put that Apple-like (x) button at the corner of a Page Sheet, but adding it to the parent view makes it appear behind the Page Sheet (and also impossible to tap) and adding it to the Page Sheet will make part of it hidden, since it's out of the view area.

有解决方案吗?

谢谢.

推荐答案

这是我使用的解决方案.它并不是您所描述的那样,它也很整洁,但是会很棘手,因为您希望按钮部分位于视图范围之外(如您所说,它必须是view-controller的子元素,视图的超级视图).

Here's a solution that I use. It's not quite what you describe, which would be neat too, but would be tricky since you'd want the button to be partially out of the view's bounds (as you say, it would have to be a child of the view-controller-view's superview).

我的解决方案是在导航栏的左侧按钮区域中放置一个关闭按钮.我通过UIViewController类扩展自动执行此操作.要使用它,只需调用[currentViewController presentAutoModalViewController:modalViewController animation:YES];

My solution is to put a close button in the left-button area of a navigation bar. I do this automagically via a UIViewController class extension. To use it, just call [currentViewController presentAutoModalViewController: modalViewController animated: YES];

@implementation UIViewController (Modal)

- (void) presentAutoModalViewController: (UIViewController *) modalViewController withDismissAction: (SEL) onDismiss animated:(BOOL)animated
{
    UINavigationController* nc = nil;
    if ( NO == [ modalViewController isKindOfClass: [UINavigationController class]] )
    {
        nc = [[[UINavigationController alloc] initWithRootViewController: modalViewController] autorelease];

        [nc setToolbarHidden:YES animated: NO];

        nc.modalPresentationStyle = modalViewController.modalPresentationStyle;

        modalViewController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
                                                                                                              target:self 
                                                                                                              action:onDismiss] autorelease];
    }
    else
    {
        nc = (UINavigationController*) modalViewController;

        UIViewController* rootViewController = [nc.viewControllers objectAtIndex: 0];
        rootViewController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
                                                                                                              target:self 
                                                                                                              action:onDismiss] autorelease];
    }

    [nc setNavigationBarHidden: NO];
    nc.navigationBar.barStyle = UIBarStyleBlack;
    nc.toolbar.barStyle = self.navigationController.navigationBar.barStyle;

    [self presentModalViewController: nc animated: animated ];
}

- (void) presentAutoModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
{
    [self presentAutoModalViewController:modalViewController withDismissAction: @selector(autoModalViewControllerDismiss:) animated: animated];
}

- (void) autoModalViewControllerDismiss: (id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}

- (BOOL) isAutoModalViewController
{
    return ( self.navigationController != nil && self.navigationController.parentViewController != nil && self.navigationController.parentViewController.modalViewController == self.navigationController );
}

@end

这篇关于将关闭按钮添加到UIModalPresentationPageSheet角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆