Re: Loop between observers with KVO from UIScrollView
Re: Loop between observers with KVO from UIScrollView
- Subject: Re: Loop between observers with KVO from UIScrollView
- From: Quincey Morris <email@hidden>
- Date: Sun, 19 Jun 2011 22:58:11 -0700
On Jun 19, 2011, at 11:59, Tales Pinheiro de Andrade wrote:
> if ([keyPath isEqualToString:@"contentOffset"]) {
> CGPoint newContentOffset = [(UIScrollView *)object contentOffset];
> newContentOffset.y = self.contentOffset.y;
> self.contentOffset = newContentOffset;
> }
It may be as simple as changing the above pattern to this pattern:
> if ([keyPath isEqualToString:@"contentOffset"]) {
> CGPoint newContentOffset = [(UIScrollView *)object contentOffset];
> newContentOffset.y = self.contentOffset.y;
> if (!CGPointEqualToPoint (self.contentOffset, newContentOffset))
> self.contentOffset = newContentOffset;
> }
But note:
1. You should really check the object (at least its class) as well as the keyPath.
2. You should really use a context parameter that's unique for your observations, and call super if the context isn't what you expect.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden