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

后端 未结 20 2043
既然无缘
既然无缘 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:50

    I created my view programmatically and this ended up working for me:

    - (void) viewDidLayoutSubviews {
        // only works for iOS 7+
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
            CGRect viewBounds = self.view.bounds;
            CGFloat topBarOffset = self.topLayoutGuide.length;
    
            // snaps the view under the status bar (iOS 6 style)
            viewBounds.origin.y = topBarOffset * -1;
    
            // shrink the bounds of your view to compensate for the offset
            viewBounds.size.height = viewBounds.size.height + (topBarOffset * -1);
            self.view.bounds = viewBounds;
        }
    }
    

    Source (in topLayoutGuide section at bottom of pg.39).

提交回复
热议问题