Core Animation problem on iPhone

Posted by Mac on Stack Overflow See other posts from Stack Overflow or by Mac
Published on 2010-03-14T23:29:24Z Indexed on 2010/03/14 23:35 UTC
Read the original article Hit count: 606

Filed under:
|

I'm new to iPhone development, and doing some experimentation with Core Animation. I've run into a small problem regarding the duration of the animation I'm attempting.

Basically, Ive got a view with two subviews, and I'm trying to animate their opacity so that one fades in while the other fades out. Problem is, instead of a gradual fade in/out, the subviews simply switch instantly to/from full/zero opacity. I've tried to adjust the animation duration with CATransaction with no noticable effect. It's also not specific to animating opacity - animating position shows the same problem.

The code I'm using (inside a method of the superview) follows:

CALayer* oldLayer = ((UIView*) [[self subviews] objectAtIndex:0]).layer;
CALayer* newLayer = ((UIView*) [[self subviews] objectAtIndex:1]).layer;

[CATransaction begin];
[CATransaction setAnimationDuration:1.0f];
oldLayer.opacity = 0.0;
newLayer.opacity = 1.0;
[CATransaction commit];

Does anyone have an idea what the problem might be?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about core-animation