How to present a semi-transparent (half-cut) viewcontroller in iOS 8

核能气质少年 提交于 2019-12-05 23:18:59

问题


in iOS 7 there is no problem for this method:

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

But in iOS 8 it did nothing.How to solve it? Is it a Bug for iOS 8?


回答1:


My answer is more simple, below code. This works in iOS8 (XCode6 GM seed).

HogeViewController *vc = [[HogeViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:vc animated:NO completion:nil];



回答2:


Note this workaround was needed on xcode6_beta7. The lastest xcode6 has the UIModalPresentationOver* styles fixed. So, I'm just assigning them to myModalViewController.modalPresentationStyle and now it works ok.

Finally made it work in iOS 8 after reading the UIPresentationController help and this post

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];

You can make the modal view controller inherit from UIViewControllerTransitioningDelegate

@interface MyModalController : UIViewController <UIViewControllerTransitioningDelegate>

and override presentationControllerForPresentedViewController:...

-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
    if (presented == self) {
        return [[TransparentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
    } else {
        return nil;
    }
}

returning an instance of TransparentPresentationController which inherits from UIPresentationController

@interface TransparentPresentationController : UIPresentationController

and overrides shouldRemovePresentersView

- (BOOL) shouldRemovePresentersView {
    return NO;
}


来源:https://stackoverflow.com/questions/24158820/how-to-present-a-semi-transparent-half-cut-viewcontroller-in-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!