iOS8之后 模态 弹出半透明模糊视图控制器

1.iOS8之后只需要设置一个最新的属性

 SecondViewController *secondVC = [[SecondViewController alloc] init];
 secondVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
 //self.tabBarController.tabBar.hidden = YES;  当presentingVC有根视图控制器tabBarController,隐藏tabBar
 secondVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.14]; 
 [self presentViewController:secondVC animated:YES completion:^{
  }];

如果当presentingVC有根视图控制器tabBarController,上面的设置会使tabBar未被覆盖,意思就好像是你有一直看到presentingVC直接导致不会走viewWiillAppear,不能在原视图即将出现时把隐藏tabBar的属性改回来。

2.在SecondViewController设置

- (void)viewDidLoad {
    [super viewDidLoad];
//模糊视图
    UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
    UIVisualEffectView *visualEffect = [[UIVisualEffectView alloc]initWithEffect:beffect];
    visualEffect.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    visualEffect.alpha = 0.7;
    [self.view addSubview:visualEffect];
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.presentingViewController.tabBarController.tabBar.hidden = NO;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容