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

前端 未结 3 2077
温柔的废话
温柔的废话 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.

提交回复
热议问题