7

在 iOS 7 中,这种方法没有问题:

_rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[_rootViewController presentViewController:self animated:NO completion:nil];

但是在iOS 8中它什么也没做。如何解决它?是iOS 8的Bug吗?</p>

4

2 回答 2

13

我的答案更简单,如下代码。这适用于 iOS8(XCode6 GM 种子)。

HogeViewController *vc = [[HogeViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:vc animated:NO completion:nil];
于 2014-09-11T17:45:38.147 回答
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];

您可以使模态视图控制器继承自 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;
}
于 2014-09-05T18:24:49.170 回答