I want build a view controller with the same animation of Contacts app in iOS 10. When you scroll down the page the contact's photo goes in the middle of navigation bar.
There is an API in iOS 10 or is a custom implementation?
I want build a view controller with the same animation of Contacts app in iOS 10. When you scroll down the page the contact's photo goes in the middle of navigation bar.
There is an API in iOS 10 or is a custom implementation?
Research
There are many techniques trying to modify the navbar. I have spent a lot of hours by trying one after another:
self.navigationController!.navigationBar.addSubview(self.titleView!)
However this looks great, it hides the navbar elements and the back button does not respond to click. I couldn't make this work eventhough I tried different layers or bringing views to front/back.Resolution
So, by my opinion, the best solution (but not the clearest one) is to:
self.navigationController!.isNavigationBarHidden = true
in viewWillAppear(_ animated: Bool)
. Also do not forget to bring it back in viewWillDisappear(_ animated: Bool)
This solution requires you to maintain your own "navbar" to look the same like the native one. Nevertheless, unlike the navbar modification, this would probably work in the future versions of iOS.
A trick could be to make the navigation bar invisible. In the storyboard set Simulated Metrics -> Top Bar = None (you could even avoid it anyway).
In your view controller add it in viewDidLoad:
Swift 3.0
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
Objective-C
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
Then you should create an animation when sliding the uitableview/uiscrollview with the detail of the contact and here it depends on what you want to do...
Edit: Here you can find an example on the simulator... sorry for the ugly mockup :D