I have a custom UIView that is added to as a subView of a UIScrollView, and I want that UIView automatically repositioned whenever the UIScrollView scrolls. In addition to observe the UIScrollView's contentOffset property(which works fine), I also need observes its dragging property:
[scrollView addObserver:self
forKeyPath:@"dragging"
options:NSKeyValueObservingOptionNew
context:NULL];
but in the observeValueForKeyPath:ofObject:change:context method, I didn't receive any NSNotification for the change of the dragging property, what's the problem here? Thanks.
Since i'm gonna reuse this custom UIView in multiple UIViewControllers, I want the custom view itself handles the repositioning logic, rather than duplicate the repositioning logic in each UIViewController's UIScrollViewDelegate methods(like scrollViewDidScroll thing).
UIKit is not KVO-compliant in general. The fact that some properties may generate change notifications isn't reliable - it's not documented and may change in future versions etc.
Since you need to reuse this reposition logic, why not separate it properly? Btw - you can place it in your custom view class itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With