UIview全屏

时间:2013-03-20 16:50:45

标签: ios

我正在使用以下代码创建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选项将其全屏设置,它也会全屏显示,除了UIWindow顶部的5cm线。这有什么理由吗?

1 个答案:

答案 0 :(得分:15)

好吧,之所以发生这种情况,是因为[[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;