UIView的全屏
我使用下面的代码创建一个UIView: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;
唯一的问题是,即使我使用mainScreen选项设置全屏幕,它全屏显示,除了5厘米行在UIWindow的顶部。这有什么理由吗?
好吧,所以发生这种情况的原因是因为[[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;
很棒的回答,我甚至都没有想过。是的,差距是状态栏的大小:) – Alessandro 2013-03-20 17:12:15
我想你想[UIScreen mainScreen] .bounds不是[UIScreen mainScreen] .applicationFrame – 2015-02-11 21:19:53
它的工作,但它显示在标签栏和导航栏下。 – 2015-02-20 15:20:40
self.view是从界面生成器 – Alessandro 2013-03-20 16:57:06
当前视图,你可以提供一个屏幕截图? – Kunal 2013-03-20 17:04:39