Status bar and navigation bar appear over my view's bounds in iOS 7

后端 未结 20 2096
既然无缘
既然无缘 2020-11-22 07:09

I recently downloaded Xcode 5 DP to test my apps in iOS 7. The first thing I noticed and confirmed is that my view\'s bounds is not always resized to account for the status

20条回答
  •  眼角桃花
    2020-11-22 07:53

    I would like to expand on Stunner's answer, and add an if statement to check if it is iOS-7, because when I tested it on iOS 6 my app would crash.

    The addition would be adding:

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    

    So I would suggest adding this method to your MyViewControler.m file:

    - (void) viewDidLayoutSubviews {
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
            CGRect viewBounds = self.view.bounds;
            CGFloat topBarOffset = self.topLayoutGuide.length;
            viewBounds.origin.y = topBarOffset * -1;
            self.view.bounds = viewBounds;
        }
    }
    

提交回复
热议问题