ios - KVO for scroll start & end in UIScrollView -
is there way use kvo (key value observing) detect scrollviewwillbegindragging , scrollviewdidenddecelerating in swift?
edit: tried
scrollview.addobserver(self, forkeypath: "dragging", options: nskeyvalueobservingoptions.new, context: nil)
but it's never called. if observe instance "contentoffset" in same way, it's called. kvc compliant?
you can add observers using nsnotification center.
in viewdidload of vc,
override func viewdidload() { super.viewdidload() nsnotificationcenter.defaultcenter().addobserver(self, selector: #selector(self.informbegindragging), name: "begin", object: nil) nsnotificationcenter.defaultcenter().addobserver(self, selector: #selector(self.informenddragging), name: "end", object: nil) }
you can in following 2 methods
func informbegindragging() { //do } func informenddragging() { //do }
and these 2 methods triggered when scroll view begin dragging or end dragging
func scrollviewdidenddragging(scrollview: uiscrollview, willdecelerate decelerate: bool) { nsnotificationcenter.defaultcenter().postnotificationname("end", object: nil) } func scrollviewwillbegindragging(scrollview: uiscrollview) { nsnotificationcenter.defaultcenter().postnotificationname("begin", object: nil) }
Comments
Post a Comment