请注意,xcode6_beta7 需要此解决方法。最新的xcode6
修复了 UIModalPresentationOver* 样式。所以,我只是将它们分配给 myModalViewController.modalPresentationStyle,现在它可以正常工作了。
在阅读了UIPresentationController help 和this post 之后,终于让它在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];
你可以让模态视图控制器继承自 UIViewControllerTransitioningDelegate
@interface MyModalController : UIViewController <UIViewControllerTransitioningDelegate>
并覆盖presentationControllerForPresentedViewController:...
-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
if (presented == self) {
return [[TransparentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
} else {
return nil;
}
}
返回一个继承自 UIPresentationController 的 TransparentPresentationController 实例
@interface TransparentPresentationController : UIPresentationController
并覆盖 shouldRemovePresentersView
- (BOOL) shouldRemovePresentersView {
return NO;
}