如何模态出一个半透明页面

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yst19910702/article/details/83176398

一般在做自定义弹框时或者点击展示大图时用的较多。不说了上代码https://github.com/YST521/DEMOLIST.git

//第一步A页面跳转到B页面

           MOdalPopController * popVC = [MOdalPopController new];

            popVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];

            popVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;

            self.modalPresentationStyle = UIModalPresentationCurrentContext;

[self presentAnimal]; //跳转动画

[self.navigationController presentViewController:popVC animated:NO completion:nil];

//

-(void)presentAnimal{

    CATransition *animation = [CATransition animation];

    animation.duration = 0.3;

    animation.type = kCATransitionFade;

    animation.subtype = kCATransitionFromTop;

    [self.view.window.layer addAnimation:animation forKey:nil];

    [self dismissViewControllerAnimated:NO completion:0];

}

//如果[self.navigationController presentViewController:popVC animated:NO completion:nil];里面动画为YES则是模态的那几种动画效果

B页面。dismiss 同样去掉了动画效果 重新添加了动画

-(void)dismiss{

    CATransition *animation = [CATransition animation];

    animation.duration = 0.3;

    animation.type = kCATransitionFade;

    animation.subtype = kCATransitionFromTop;

    [self.view.window.layer addAnimation:animation forKey:nil];

    [self dismissViewControllerAnimated:NO completion:0];

}

猜你喜欢

转载自blog.csdn.net/yst19910702/article/details/83176398