Search code examples
iphoneobjective-canimationcore-animation

Is it possible to animate a property in a subclass of UIView with Core Animation


I have made a subclass of UIView and i'm trying to animate a property in that subclass.

The property is used in drawRect and I want drawRect to execute at each step of the animation. So I made it the property setter like this:

-(void) setFill:(float) f
{
    fill = f;
    [self setNeedsDisplay];
}

But when I run the animation block the property get set right away. What am I doing wrong?

Animation call looks like this:

[UIView animateWithDuration:3.0f
                          delay:0.0f
                        options: UIViewAnimationOptionCurveLinear
                     animations: ^{ circle1.fill = 50; }
                     completion: ^(BOOL finished) { }];

Is this the right way to go animating your UIView subclasses?


Solution

  • Only certain properties of UIView are animatable (frame, center, transform...). You have to write your own animation to animate your custom properties using NSTimer.