Photos of iOS 10 contacts in the navigation bar

I want to create a view controller with the same animation of the Contacts application in iOS 10. When you scroll down the page, the contact photo goes in the middle of the navigation bar.

Is there an API in iOS 10 or is it a custom implementation?

+6
source share
2 answers

Study

There are many methods that try to change the navigation bar. I spent many hours trying one by one:

Resolution

So, in my opinion, the best solution (but not the clearest) is:

  • Create your own custom view (XIB) that looks like the navigator itself - as in option 3. above. Include your own implementation of the back button, etc.
  • Hide source navigator: self.navigationController!.isNavigationBarHidden = true in viewWillAppear(_ animated: Bool) . Also remember to return it to viewWillDisappear(_ animated: Bool)
  • Place your own view on top of the screen. Not lower than the top layout guide, but actually on top of the screen. Your viewer underlines the status bar. Use the top mark of your view to match the contents of the status bar.
  • Implement animation as they say in the scroll event of a UITableView

This solution requires your own “navigator” to look the same as your native one. However, unlike the navbar modification, this is likely to work in future versions of iOS.

+3
source

The trick may be to make the navigation bar invisible. In the Simulated Metrics storyboard set → Top Bar = None (you can even avoid this).

enter image description here

In your view, the controller adds it to 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 have to create the animation while moving the uitableview / uiscrollview with the contact details, and here it depends on what you want to do ...

Edit: Here you can find an example on the simulator ... sorry for the ugly layout: D enter image description here

+2
source

Source: https://habr.com/ru/post/1014246/


All Articles