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
Post a Comment