How to Key-Value-Observe the rotation of a CALayer?
- by HelloMoon
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?