创建一个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; }}片新闻热点
疑难解答