Watch scrolling by dragging a property but not receiving notification

I have a custom UIViewone that is added as subViewfor UIScrollView, and I want it to UIViewautomatically move whenever it scrolls UIScrollView. Besides observing a property UIScrollView's contentOffset(which works great), I also need to observe its property dragging:

[scrollView addObserver:self 
             forKeyPath:@"dragging" 
                options:NSKeyValueObservingOptionNew 
                context:NULL];

but in the method observeValueForKeyPath:ofObject:change:contextI did not receive any NSNotificationproperty changes dragging, what is the problem here? Thank.

updated

Since I am going to reuse this custom one UIViewin several UIViewControllers, I want the user view to handle the repositioning logic itself, rather than duplicating the repositioning logic in each method UIViewController's UIScrollViewDelegate(for example, a scrollViewDidScrollthing).

+5
source share
2 answers

UIKit is not generally KVO-compatible. The fact that some properties may generate change notifications is not reliable - it is 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 put it in your own view class.

+4

UIScrollView scrollViewDidScroll:

0

All Articles