0

I'm supporting both iOS 7 and iOS 8 in my app and using storyboard with autolayout to setup my views. I'm having an issue with iOS 7 only.

I have a subview which has a constraint that sets its top space to the bottom of the top layout guide. This makes sure that the subview does not go underneath the translucent navigation bar at the top. It works fine on iOS 8, however on iOS 7 the subview goes underneath the navigation bar right below the status bar.

Any advice on how I can make this work on iOS 7 as well?

codeman
  • 8,868
  • 13
  • 50
  • 79

1 Answers1

0

Currently I'm using a hack to get this to work on iOS 7, which is below:

override func viewDidLayoutSubviews() {
        if NSProcessInfo.instancesRespondToSelector(Selector("isOperatingSystemAtLeastVersion:")) {
            // iOS 7 navBar hack
        } else {     
            let navBarHeight = self.navigationController?.navigationBar.intrinsicContentSize().height
            self.navHeightConstraint.constant = navBarHeight!
            self.view.layoutSubviews()
        }
}

Basically I connected the constraint through Interface Builder and I adjust it's constant to the height of the navigation bar if it's iOS 7. If anyone has a better way, please let me know.

codeman
  • 8,868
  • 13
  • 50
  • 79