How to Key-Value-Observe the rotation of a CALayer?
Posted
by HelloMoon
on Stack Overflow
See other posts from Stack Overflow
or by HelloMoon
Published on 2009-08-11T14:23:43Z
Indexed on
2010/05/29
9:02 UTC
Read the original article
Hit count: 300
I can access the value like this:
NSNumber* rotationZ = [myLayer valueForKeyPath:@"transform.rotation.z"];
But for some reason, if I try to KV-observe that key path, I get a compiler error. First, this is how I try to do it:
[myLayer addObserver:self forKeyPath:@"transform.rotation.z" options:0 context:nil];
The compiler tells me:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ addObserver: forKeyPath:@"rotation.z" options:0x0 context:0x528890] was sent to an object that is not KVC-compliant for the "rotation" property.'
what I don't get is, why I can access that z value by KVC key path, but not add an observer to it. Does this make sense?
How else could I observe the z value of that matrix? I don't care about the other values of the matrix. Only the z rotation. Any other way to access and observe it?
© Stack Overflow or respective owner