【发布时间】:2011-03-15 11:23:51
【问题描述】:
当我将一个视图(view1)添加到另一个视图(view2)时,我发现一个错误: 如果状态栏没有隐藏,添加视图(view1)后,下面的view1可以出现20像素高的空栏。 如果状态栏被隐藏,这种现象就消失了。 谁能帮我解决这个问题。 想你!
【问题讨论】:
标签: iphone objective-c cocoa-touch uiview uistatusbar
当我将一个视图(view1)添加到另一个视图(view2)时,我发现一个错误: 如果状态栏没有隐藏,添加视图(view1)后,下面的view1可以出现20像素高的空栏。 如果状态栏被隐藏,这种现象就消失了。 谁能帮我解决这个问题。 想你!
【问题讨论】:
标签: iphone objective-c cocoa-touch uiview uistatusbar
只需检查状态栏是否隐藏并通过添加 20 个像素来调整第二个 UIView 的框架
if([[UIApplication sharedApplication] isStatusBarHidden])
view2.frame = CGRect(x,y,width,height);
else
view2.frame = CGRect(x,y+20,width,height);
【讨论】:
作为一个更具体的例子,我有一个案例,在应用程序启动后,我实际上还没有准备好让用户看到屏幕上发生的事情。在这种情况下,我有一个仍在渲染的 web 视图,所以我将 Default.png 文件覆盖到我的视图上,同时在后台发生了一些垃圾。
// put the default image over the whole screen while we wait for the html to load
UIImageView * defaultImageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"Default.png"]] ;
[self.view addSubview:defaultImageView];
// adjust for status bar
if(![[UIApplication sharedApplication] isStatusBarHidden]) {//http://stackoverflow.com/questions/5310975/iphone-view-and-statusbar
CGRect imageRect = defaultImageView.frame;
imageRect.origin.y = imageRect.origin.y - 20;
defaultImageView.frame = imageRect;
}
Now, later in the code, remove the subview....
【讨论】: