In my iOS application, I observe changes in the contentOffset property of my scrollView subclass. My observer handler looks like this:
- (void)observeContentOffsetHandler:(id)aContentOffset { NSLog(@"%@", aContentOffset); }
I chose the parameter for the method arbitrarily as id for simplicity.
My NSLog'ging is as follows:
-[MyScrollView observeContentOffsetHandler:] [Line 111] NSPoint: {296, 375} -[MyScrollView observeContentOffsetHandler:] [Line 111] NSPoint: {296, 389} -[MyScrollView observeContentOffsetHandler:] [Line 111] NSPoint: {295, 401} -[MyScrollView observeContentOffsetHandler:] [Line 111] NSPoint: {291, 415}
I need to use the x and y values, but I have no idea how to get to them. I tried pouring the identifier in CGPoint, no. I tried changing the parameter to CGPoint, nope.
UPDATE
Deeper and deeper. @mgold no joy. This is how I set up the observation:
self.contentOffsetObserver = [[[Observer alloc] initWithTarget:self action:@selector(observeContentOffsetHandler:)] autorelease]; [self.myScrollViewSubclass addObserver:self.contentOffsetObserver forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];
The observer is a convenient class that I use to simplify observation. Note the observer callback observContentOffsetHandler:. When I change the signature of this method to the current one:
- (void)observeContentOffsetHandler:(id)aContentOffset
in the @mgold CGPoint suggestion:
- (void)observeContentOffsetHandler:(CGPoint)aContentOffset
This is not true, as NSLog shows with all zeros for aContentOffset:
-[MyScrollController observeContentOffsetHandler:] [Line 74] aContentOffset 0 0 -[MyScrollController observeContentOffsetHandler:] [Line 74] aContentOffset 0 0 -[MyScrollController observeContentOffsetHandler:] [Line 74] aContentOffset 0 0 -[MyScrollController observeContentOffsetHandler:] [Line 74] aContentOffset 0 0
Not sure if my move is here.