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

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

    I have a scenario where I use the BannerViewController written by Apple to display my ads and a ScrollViewController embedded in the BannerViewController.

    To prevent the navigation bar from hiding my content, I had to make two changes.

    1) Modify BannerViewController.m

    - (void)viewDidLoad
    {
       [super viewDidLoad];
       float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
       if (systemVersion >= 7.0) {
          self.edgesForExtendedLayout = UIRectEdgeNone;
       }
    }
    

    2) Modify my ScrollViewContoller

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
        if (systemVersion >= 7.0) {
            self.edgesForExtendedLayout = UIRectEdgeBottom;
        }
    }
    

    Now the ads show up correctly at the bottom of the view instead of being covered by the Navigation bar and the content on the top is not cut off.

    0 讨论(0)
  • 2020-11-22 07:43

    In your apps plist file add a row, call it "View controller-based status bar appearance" and set it to NO.

    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2020-11-22 07:51

    edgesForExtendedLayout does the trick for iOS 7. However, if you build the app across iOS 7 SDK and deploy it in iOS 6, the navigation bar appears translucent and the views go beneath it. So, to fix it for both iOS 7 as well as for iOS 6 do this:

    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;   // iOS 7 specific
    
    0 讨论(0)
  • 2020-11-22 07:51

    Add the key "View Controller-based status bar appearance" from the dropdownlist as a row in info.plist. Something like this:

    Enter image description here

    0 讨论(0)
  • 2020-11-22 07:52

    To me, the simplest solution is to add two keys into the plist

    enter image description here

    0 讨论(0)
提交回复
热议问题