swift - How to mimic `UITableViewController` showing of the large titles in `navigationBar` on iOS 11 -


i'm trying use preferslargetitles ios 11 in application. works expected in subclasses of uitableviewcontroller:

navigationcontroller?.navigationbar.preferslargetitles = true 

however, in 1 case needed subclass uiviewcontroller , add table view myself. in situation needed constraint table view myself:

tableview.topanchor.constraint(equalto: self.view.safearealayoutguide.topanchor).isactive = true tableview.leftanchor.constraint(equalto: self.view.leftanchor).isactive = true tableview.rightanchor.constraint(equalto: self.view.rightanchor).isactive = true tableview.bottomanchor.constraint(equalto: self.otherview.topanchor).isactive = true 

while these constraints present tableview expect, navigation bar uses large title. mimic behavior of uitableviewcontroller, when tableview scrolled top, large title presented, otherwise title collapses normal one.

how solve this?

seems have been able emulate behavior more or less closely enough. implementing delegate method tableview reacts scrolling, , running code uses current contentoffset either show, or hide large title (uitableview inherits uiscrollview, scrollview parameter refers in case tableview):

func scrollviewdidscroll(_ scrollview: uiscrollview) {     if scrollview.contentoffset.y <= 0 {         self.navigationitem.largetitledisplaymode = .always     } else {         self.navigationitem.largetitledisplaymode = .never     }     self.navigationcontroller?.navigationbar.setneedslayout()     self.view.setneedslayout()     uiview.animate(withduration: 0.25, animations: {         self.navigationcontroller?.navigationbar.layoutifneeded()         self.view.layoutifneeded()     }) } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -