Sup*_*ppy 7 uimodalpresentationstyle presentviewcontroller ios8
在iOS 7中,此方法没有问题:
_rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[_rootViewController presentViewController:self animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是在iOS 8中它没有做任何事情.如何解决?这是iOS 8的Bug吗?
小智 13
我的答案更简单,代码如下.这适用于iOS8(XCode6 GM种子).
HogeViewController *vc = [[HogeViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:vc animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)
小智 3
请注意,xcode6_beta7 上需要此解决方法。最新的 xcode6 修复了 UIModalPresentationOver* 样式。所以,我只是将它们分配给 myModalViewController.modalPresentationStyle,现在它可以正常工作了。
阅读UIPresentationController 帮助和这篇文章后,终于让它在 iOS 8 中工作了
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
MyModalController *myModalController = [[MyModalController alloc] initWithNibName:@"MyModalController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myModalController];
navController.modalPresentationStyle = UIModalPresentationCustom;
navController.transitioningDelegate = myModalController;
[self.navigationController presentViewController:navController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
您可以使模态视图控制器继承自 UIViewControllerTransitioningDelegate
@interface MyModalController : UIViewController <UIViewControllerTransitioningDelegate>
Run Code Online (Sandbox Code Playgroud)
并覆盖presentationControllerForPresentedViewController:...
-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
if (presented == self) {
return [[TransparentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
} else {
return nil;
}
}
Run Code Online (Sandbox Code Playgroud)
返回继承自UIPresentationController的TransparentPresentationController的实例
@interface TransparentPresentationController : UIPresentationController
Run Code Online (Sandbox Code Playgroud)
并覆盖shouldRemovePresentersView
- (BOOL) shouldRemovePresentersView {
return NO;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8570 次 |
| 最近记录: |