开发者

iphone View and statusbar

When i add one view(view1) to another view(view2), i find a error: If the status bar is not hidden, after add the view(view1), bellow view1 can appear 20 pixel hight null bar. If the status bar is hidden, this phenomenon disappear. Who can help me to resolve this question. t开发者_JS百科hink you!


Just check if the statusbar is hidden and adjust the frame of your second UIView by adding 20 pixels

if([[UIApplication sharedApplication] isStatusBarHidden])
        view2.frame = CGRect(x,y,width,height);
    else
        view2.frame = CGRect(x,y+20,width,height);


As a more concrete example, I have a case where, after the application has launched, I'm actually not quite ready for the user to see what is happening on the screen. In this case, I have a webview that is still rendering, so I overlay the the Default.png file onto my view while some junk happens in the background.

// 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....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜