Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My CALayer transform holds after animation, but the perspective disappears

I have the following code that rotates a CALayer by -45degrees on the Y axis:

#define D2R(x) (x * (M_PI/180.0))

- (void) swipe:(UISwipeGestureRecognizer *)recognizer
{        
    CATransform3D transform = CATransform3DMakeRotation(D2R(-45), 0, 1.0, 0);
    transform.m34 = -1.0 / 850;

    CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"];
    transformAnimation.fillMode = kCAFillModeForwards;
    transformAnimation.removedOnCompletion = NO;
    transformAnimation.toValue = [NSValue valueWithCATransform3D:transform];
    transformAnimation.duration = 0.5;

    [self.layer addAnimation:transformAnimation forKey:@"transform"];
}

The animation works, except it ends with no perspective - ignoring my m34 setting if I'm understanding things correctly.

Halfway through:

enter image description here

At the end:

enter image description here

What am I doing wrong?

like image 725
ConfusedNoob Avatar asked Apr 19 '13 20:04

ConfusedNoob


1 Answers

Animation only affects the appearance of the view during the animation. It doesn't get applied to the view after the animation ends. You need to do this yourself. I'm guessing something like this right after adding the animation will work:

self.layer.transform = transform;

You can do this right away, as the animation will hide it until the animation completes.

like image 189
Dave Batton Avatar answered Oct 27 '22 01:10

Dave Batton