Presenting semi-transparent viewcontroller that works both in iOS7 and iOS8

前端 未结 3 1328
花落未央
花落未央 2020-12-14 20:05

I had the following code that worked perfectly in iOS7.

[UIView animateWithDuration:0.5 animations:^(void) {
    self.view.alpha = 0.5;
    [self.navigation         


        
3条回答
  •  感动是毒
    2020-12-14 20:58

    Based on @Tiguero's answer, I created a small category class to solve the problem.

    @implementation UIViewController (Extensions)
    
    - (void) presentTransparentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
    {
        if(SYSTEM_VERSION_LESS_THAN(@"8.0")) {
            self.parentViewController.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
        }else{
            viewControllerToPresent.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        }
    
        [self presentViewController:viewControllerToPresent animated:YES completion:completion];
    }
    
    @end
    

    The iOS7 version required me to hardcode the controller that does the presenting.

提交回复
热议问题