There are a few questions and answers on StackOverflow about custom animatable properties, but I haven't been able to effectively use their answers / solutions.
In short, I'd like to have a UIControl
with some properties that I can put in an animation block (e.g. [UIView animateWithDuration:...
) and have it behave as some of UIKit's controls (e.g. UISlider
) do.
For example, I'd like to do something like,
TASlider *myCustomSlider = [[TASlider alloc] init];
myCustomSlider.value = 0.f;
[UIView animateWithDuration:2.f animations:^{
myCustomSlider.value = 0.f;
}];
and have it “just work”. TASlider
would be a UIControl
subclass and it would have a public property value
and a private property myKnob
(which is a UIView
or CALayer
subclass). The above code would animate the private subview or sublayer myKnob
when the value
property was modified in the animation block.
I've researched this a bit but I guess I can't quite put the pieces together to do what I'd like.
Could someone put together a “Hello World” of custom animatable CALayer
properties on a UIView
/ UIControl
subclass?