Here's the setup: I have a subclass of IKImageBrowserView whose zoomValue
property is bound to a key VFBrowserZoomValue
in the shared NSUserDefaultsController
. I have an NSSlider
whose value
binding is bound to the same key.
This works perfectly to change the zoomValue
of the browser from the slider.
I'm trying to implement -magnifyWithEvent:
in my IKImageBrowserView
subclass to allow zooming the browser with the pinch gesture on trackpads.
Here's my implementation:
-(void)magnifyWithEvent:(NSEvent *)event
{
if ([event magnification] > 0) {
if ([self zoomValue] < 1) {
[self setZoomValue: [self zoomValue] + [event magnification]];
}
}
else if ([event magnification] < 0) {
if ([self zoomValue] + [event magnification] > 0.1) {
[self setZoomValue: [self zoomValue] + [event magnification]];
}
else {
[self setZoomValue: 0.1];
}
}
}
This changes the browser's zoomValue
correctly. The problem is that the NSUserDefaults
is not updated with the new value.
Elsewhere in the app, I have an implementation of -observeValueForKeyPath:ofObject:change:context:
that observes the browser's zoomValue
. If I log the values of the browser's zoom, the slider's value and the key in defaults in that method, I see that the browser's zoomValue has not been pushed into NSUserDefaults and the slider hasn't updated.
I've tried surrounding the -magnifyWithEvent:
method with calls to -{will,did}ChangeValueForKey
to no effect.