Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

observe scroll view's 'dragging' property but received no notification

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.

updated

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).

like image 914
Pwn Avatar asked Jul 13 '12 14:07

Pwn


1 Answers

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.

like image 73
Max O Avatar answered Nov 01 '22 16:11

Max O