iOS 7 Navigation Bar and Scroll View are different in storyboard and simulator

前端 未结 3 2069
温柔的废话
温柔的废话 2021-01-16 08:14

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 Sto

相关标签:
3条回答
  • 2021-01-16 09:04
    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.

    0 讨论(0)
  • 2021-01-16 09:04

    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

    0 讨论(0)
  • 2021-01-16 09:14

    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

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