views:

76

answers:

1

i.e. I have a layer's "transform.rotation.z" value which may change several times. Every time that value changes, I'd like to call a method. Of course I could call it just at any point where I touch that value. But maybe there's a more elegant way in objective-c / cocoa-touch? Somebody told me a few days ago that there's some notification mechanism available. But is that useful for something like this? How would it look like?

+4  A: 

I think what you want is Key-Value Observing.

invalidname
+1 for making me question my worldview - I didn't know KVO was present on the phone. I guess that's because Bindings isn't used in the SDK, so I made a rash assumption.
Graham Lee
Thx! I was reading about KVO that "direct ivar access does not produce notifications". Can you tell how I would have to access the transform.rotation.z of the transform matrix of an view if I wanted to observe that keyPath?
HelloMoon
Doesnt work! I tried it. "transform.rotation.z" as keyPath is not KVO-compliant.
HelloMoon
Sorry about that. What's weird is that if you observe key path "transform.rotation" instead of "transform.rotation.z", it thinks it's KVO-compliant, but you get this verbose error "An instance 0xd41f50 of class NSConcreteValue is being deallocated while key value observers are still registered with it. Observation info is being leaked, and may even become mistakenly attached to some other object. " Might be worth a bug report / feature request to make transform.rotation.z observable.
invalidname
As a workaround add a property for "z" that simply sets the real transform z, then make that KVO compliant...I'd file a Radar on that though.
Kendall Helmstetter Gelner