views:

73

answers:

1

I want to use CATransition to provide a fading animation between different states of a view. However, this doesn't seem to work with a single view (all examples I found use CATransition to switch between different views). In contrast, a CABasicAnimation works just fine.

My example code shows what I'm doing. I have a custom view (TTView) with two properties I want to animate. One is a color, animated using CABasicAnimation (simple interpolation). The other is a boolean state, and I want to achieve a fading effect when it changes. (Ignore the fact that the example uses it to just change a rectangle's size, that's just to keep it simple.)

Am I doing something wrong, or does CATransition just not work within a single view?

A: 

The code is a bit large, but here are the most relevant parts of the TTView implementation. The scale property is the boolean value whose change I want to animate with a transition.

+ (id) defaultAnimationForKey: (NSString *)key
{
  if ([key isEqualToString: @"color"]) {
    return [CABasicAnimation animation];

  } else if ([key isEqualToString: @"scale"]) {
    return [CATransition animation];
  }

  return [super defaultAnimationForKey:key];
}

/* ... */

- (IBAction) toggleScale: (id)sender
{
  [[self animator] setScale: !self.scale];
}

I just noticed that CATransition is not a subclass of CAPropertyAnimation, so perhaps that's my real problem.

Jens Kilian