我正在使用以下代码创建UIview:
UIview* baseView = [[UIview alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//self.view = baseView;
[self.view addSubview:baseView];
[baseView setBackgroundColor:[UIColor blackColor]];
baseView.userInteractionEnabled = YES;
baseView.alpha = 0.7;
Run Code Online (Sandbox Code Playgroud)
唯一的问题是即使我使用mainScreen选项将其设置为全屏,它也会全屏显示,除了UIWindow顶部的5cm线.这有什么理由吗?
Pet*_*tar 16
好的,所以之所以发生这种情况,是因为[[UIScreen mainScreen] applicationFrame]如果可见,将返回窗口框架减去状态栏的大小.
要修复它,一个简单的方法是:
UIView* baseView = [[UIView alloc] initWithFrame:CGRectMake(0,
0,
[[UIScreen mainScreen] applicationFrame].size.width,
[[UIScreen mainScreen] applicationFrame].size.height)];
//self.view = baseView;
[self.view addSubview:baseView];
[baseView setBackgroundColor:[UIColor blackColor]];
baseView.userInteractionEnabled = YES;
baseView.alpha = 0.7;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18082 次 |
| 最近记录: |