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];
}
打完收工。
本文介绍如何在iOS应用中实现一个半屏显示且透明的视图控制器。通过设置特定的属性和重写布局方法,可以使得视图只占据屏幕下半部分,并保持透明效果。
2万+

被折叠的 条评论
为什么被折叠?



