将关闭按钮添加到UIModalPresentationPageSheet角

编程入门 行业动态 更新时间:2024-10-10 19:19:53
本文介绍了将关闭按钮添加到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角

本文发布于:2023-11-09 04:07:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   UIModalPresentationPageSheet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!