iOS presentViewController 推出半屏幕透明 UIViewController
不废话,直接上代码
1.父页面打开方式
/** * 页面打开配置 * * @param sender <#sender description#> */ - (IBAction)shwoViewAction:(id)sender { TTViewController *tView = [[TTViewController alloc] init]; //设置模式展示风格 [tView setModalPresentationStyle:UIModalPresentationOverCurrentContext]; //必要配置 self.modalPresentationStyle = UIModalPresentationCurrentContext; self.providesPresentationContextTransitionStyle = YES; self.definesPresentationContext = YES; [self presentViewController:tView animated:YES completion:nil]; }
2.子页面重写viewWillLayoutSubviews,设置位置宽高
#define DeviceHeight [[UIScreen mainScreen] bounds].size.height #define DeviceWidth [[UIScreen mainScreen] bounds].size.width /** * 设置位置宽高 */ - (void)viewWillLayoutSubviews { self.view.frame = CGRectMake(self.view.frame.origin.x, DeviceHeight / 2, DeviceWidth, DeviceHeight / 2); //self.view.backgroundColor = [UIColor clearColor]; //self.view.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.868f]; }
打完收工。