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

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -