4

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?

Community
  • 1
  • 1
Tim Arnold
  • 8,359
  • 8
  • 44
  • 67
  • 4
    I think the other answer you refer to, is pretty good for doing what you want. 1. Subclass CALayer, 2. Create a @dynamic property, 3. Override setNeedsDisplayForKey. Like here http://stackoverflow.com/a/2396461/2462469 – Rob van der Veer Jul 29 '13 at 21:14
  • 4
    @RobvanderVeer that is almost a full answer, please post! This question in for UIView, that one is CALayers, and you are providing the glue – William Entriken Mar 05 '14 at 04:15

0 Answers0