将closuresbutton添加到UIModalPresentationPageSheetangular落
有没有办法在UIModalPresentationPageSheet的angular落添加一个button? 我的意思是,我想把类似苹果的(x)button放在页面的一angular,但将它添加到父视图使其显示在页面的后面(也不可能点击)并将其添加到页面由于它不在视野范围内,因此图表会隐藏其中的一部分。
有解决scheme吗?
谢谢。
这是我使用的解决scheme。 这并不完全是你所描述的,也可能是整洁的,但是会很棘手,因为你希望button部分地超出视图的边界(就像你说的,它必须是视图控制器的子元素)视图的超级视图)。
我的解决scheme是在导航栏的左键区域放一个closuresbutton。 我通过UIViewController类扩展自动做到这一点。 要使用它,只需调用[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
编辑:其实,我会build议你做的第一件事是使用一种不同types的closuresbutton。 例如,您可以使用Done
button在顶部添加一个工具栏。
如果你仍然想要苹果风格的浮动X,然后尝试设置属性,以确保它不会被隐藏或剪裁。 我会说更好的方法是创build一个带有前景图像(这是样式化的button图像)的UIButton
,以及从页面的背景颜色/图案渐变为button周围的透明背景的背景图像。 它实际上给你一个“浮动closuresbutton”,而不必超出页面的范围。
我发现@ TomSwift的build议非常有帮助。 这是一个使用非弃用iOS7方法和ARC的版本。
@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]; [nc setToolbarHidden:YES animated: NO]; nc.modalPresentationStyle = modalViewController.modalPresentationStyle; modalViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:onDismiss]; } else { nc = (UINavigationController*) modalViewController; UIViewController* rootViewController = [nc.viewControllers objectAtIndex: 0]; rootViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:onDismiss]; } [nc setNavigationBarHidden: NO]; nc.navigationBar.barStyle = UIBarStyleBlack; nc.toolbar.barStyle = self.navigationController.navigationBar.barStyle; [self presentViewController:nc animated:animated completion:nil]; } - (void)presentAutoModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated { [self presentAutoModalViewController:modalViewController withDismissAction: @selector(autoModalViewControllerDismiss:) animated: animated]; } - (void)autoModalViewControllerDismiss: (id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } - (BOOL)isAutoModalViewController { return ( self.navigationController != nil && self.navigationController.parentViewController != nil && self.navigationController.parentViewController.presentedViewController == self.navigationController ); } @end
我称之为…
MyController *vc = [[MyController alloc] init]; vc.modalPresentationStyle = UIModalPresentationFormSheet; vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentAutoModalViewController:info animated:YES];