iOS 7 Navigation Bar and Scroll View are different

2019-02-20 18:25发布

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:

enter image description here

This is in simulator:

enter image description here

3条回答
2楼-- · 2019-02-20 18:55

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

查看更多
我命由我不由天
3楼-- · 2019-02-20 18:56

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

Your Storyboard

You will output as below

enter image description here

查看更多
贪生不怕死
4楼-- · 2019-02-20 18:56
  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) enter image description here
  3. hook up Transparent View's height constraint (which is 64) to your ViewController Class as a IBOutlet: enter image description here
  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 enter image description here
  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.

查看更多
登录 后发表回答