ios - Stick UIView to top of screen -


i try stick uiview top of screen.

i use following code:

import uikit  class viewcontroller: uiviewcontroller, uiscrollviewdelegate {  var navigationbaroriginaloffset : cgfloat?  @iboutlet weak var navigationbar: uiview! @iboutlet weak var scrollview: uiscrollview!  override func viewdidload() {     super.viewdidload()     scrollview.delegate = self     // additional setup after loading view, typically nib. }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  override func viewwillappear(animated: bool) {     super.viewwillappear(animated)     navigationbaroriginaloffset = navigationbar.frame.origin.y }  func scrollviewdidscroll(scrollview: uiscrollview) {     navigationbar.frame.origin.y = max(navigationbaroriginaloffset!, scrollview.contentoffset.y)     print("did scroll") } } 

but view doesn't stick, scrolls scrollview.

how can make stick?

you can add constraints of view want stick main view or top layout guide. trick


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -