首页 > 学院 > 开发设计 > 正文

present半透明视图

2019-11-07 23:32:38
字体:
来源:转载
供稿:网友

创建一个UiViewController类别,在类别中添加该方法,用的时候直接调用即可

//PResent出半透明的ViewController 参数信息分别为:controller:视图控制器 flag:是否有动画 alpha:背景透明度 block:跳转时要执行的block-(void)presentTranslucentViewController:( UIViewController * _Nullable ) controller animated:(BOOL)flag alpha:(CGFloat)alpha completion:(void (^ __nullable)(void))block{ //设置背景颜色 controller.view.window.backgroundColor = [UIColor clearColor]; controller.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:alpha]; //版本适配 if (RTK_IOS_Verion >=8) { //以下代码设置透明效果 self.modalPresentationStyle = UIModalPresentationOverCurrentContext; self.definesPresentationContext = YES; controller.modalPresentationStyle = UIModalPresentationOverCurrentContext; [self presentViewController:controller animated:NO completion:^{ if (block) { block(); } }]; }else { self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext; [self presentViewController:controller animated:NO completion:^{ if (block) { block(); } }]; self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen; }}片
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表