iOS 7 Navigation Bar and Scroll View are different

2019-02-20 18:50发布

问题:

I have a navigation controller with navigation bar, not translucent. I added a scroll view to the root view. But when I run the app, it show different from what I saw in StoryBoard. Everything shifted down.

This is what I saw in StoryBoard:

This is in simulator:

回答1:

Your storyboard should like this In ios 7 scroll view must be covered to entire screen
You need to put image on top edge

You will output as below



回答2:

  1. make a full screen UIScrollView, add a full screen Content View to UIScrollView
  2. add a transparent view to top of this Content View: top:0, left: 0, right: 0, equal width with scroll, height: 64(height of status bar & navigation bar)
  3. hook up Transparent View's height constraint (which is 64) to your ViewController Class as a IBOutlet:
  4. design your view as you wish; I will add a button below the navigation bar: top space to transparent view: 8, left: 8, width: 30, height: 30
  5. add code below to your ViewController Class; if the iOS version is iOS7, set Transparent View's Height Constraint to 0(zero), if it is iOS8, do nothing:
- (void) updateViewConstraints {
    [super updateViewConstraints];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
        _transparentTopViewYConstraint.constant = 0;
    }
}

as a result, all your view's top space is relative to Transparent View, if system version is iOS7, your Transparent View's height will be 0(zero) and your views are move to top, top space will be just 8 for my example, so your views place just below the navigation bar. if system version is iOS8, your Transparent View's height will be 64 and your view's top space will be 8 + 64, so your views place just below the navigation bar again.



回答3:

please check the following:

  1. is auto layout on? then turn it off

  2. Are you using a simulator of different size? (story board is for 4 inch, while simulator is 3.5 inch) if that so, many things are to set up like turning off autoSizing right and bottom constraints

Hope this helps