Created
November 26, 2017 16:33
-
-
Save meyusufdemirci/5b24fdfebe54354efef3f66bc107dcef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class StickyHeaderView: UIView { | |
weak var parent: StickyHeader? | |
internal static var KVOContext = 0 | |
override func willMove(toSuperview view: UIView?) { | |
if let view = self.superview, view.isKind(of:UIScrollView.self), let parent = self.parent { | |
view.removeObserver(parent, forKeyPath: "contentOffset", context: &StickyHeaderView.KVOContext) | |
} | |
} | |
override func didMoveToSuperview() { | |
if let view = self.superview, view.isKind(of:UIScrollView.self), let parent = parent { | |
view.addObserver(parent, forKeyPath: "contentOffset", options: .new, context: &StickyHeaderView.KVOContext) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment