Search code examples
swiftuiscrollviewios9navigationbar

ScrollView and Navigation Bar ios9


I have a View Controller (named View2) embedded in a Navigation Controller. In this view I have a ScrollView which covers all the view (including the navigation bar).

This View Controller is presented from another view with the call:

let view2 = self.storyboard?.instantiateViewControllerWithIdentifier("View2") as! View2
let modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CrossDissolve
let nav: UINavigationController = UINavigationController.init(rootViewController: view2)
nav.modalTransitionStyle = modalStyle
self.presentViewController(nav, animated: true, completion: nil)

In my View2, I adjust the navigation bar to be translucent:

navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.translucent = true

But there is an issue, when View2 appears, the scrollview starts bellow the navigation bar. I have to tapp one time on the scrollview to see it auto-adjust at the top of the screen, over the navigation bar.

Any idea to fix it?

I want than the scrollview appears at the top of the screen, over the translucent navigation bar.

Thank you for your feedbacks,

Thomas


Solution

  • Did you try setting automaticallyAdjustsScrollViewInsets = false on your view controller?

    Another option would be to uncheck the option "Under Top Bar" in the view controller's attributes inspector in "Extend Edges".

    Hope this helps.