首页 > 技术文章 > IOS 弹出模态透明的ViewController

mythings 2016-02-01 20:49 原文

ViewController *vcObj = [[ViewController alloc] initWithNibName:NSStringFromClass([ViewController class]) bundle:nil];
    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vcObj];
    
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        
        navCon.providesPresentationContextTransitionStyle = YES;
        navCon.definesPresentationContext = YES;
        navCon.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        
        [self presentViewController:navCon animated:NO completion:nil];
    }
    else {
        
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        [self presentViewController:navCon animated:NO completion:^{
            [navCon dismissViewControllerAnimated:NO completion:^{
                appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
                [self presentViewController:navCon animated:NO completion:nil];
                appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
                
            }];
        }];
    }

推荐阅读