美文网首页
利用模态弹出VC实现类似AlertView的透明黑色背景

利用模态弹出VC实现类似AlertView的透明黑色背景

作者: 小黄人写代码 | 来源:发表于2016-05-27 19:00 被阅读63次
  • iOS 7:利用AppDelegate
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
UIViewController *vc = [[UIViewController alloc] init];
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[appDelegate.window.rootViewController presentViewController:vc animated:YES completion:^{
    vc.view.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8];
    appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
}];
  • iOS 8:利用最新的modalpresentationstyle:UIModalPresentationOverCurrentContext
TestController *vc = [[TestController alloc] init];
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:vc animated:NO completion:^{
        vc.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.8];
}];

相关文章

网友评论

      本文标题:利用模态弹出VC实现类似AlertView的透明黑色背景

      本文链接:https://www.haomeiwen.com/subject/nblfdttx.html