CATransformLayer doesn't support implicit animation?
Here's my animation code:
CGFloat zDistance = 850;
CGFloat scaleFactor = BACK_COVER_WIDTH / self.transformLayer.bounds.size.width;
CATransform3D rotation = CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0);
CATransform3D scale = CATransform3DMakeScale(scaleFactor, scaleFactor, 0.0);
CATransform3D transform = CATransform3DConcat(rotation, scale);
transform.m34 = 1.0 / -zDistance;
CGPoint location = CGPointMake(CGRectGetMidX(self.layer.frame), CGRectGetMidY(self.layer.frame));
[CATransaction begin];
[CATransaction setAnimationDuration:1.0];
self.transformLayer.transform = transform;
self.transformLayer.position = location;
[CATransaction commit];
self.transformLayer
is a CATransformLayer
with two sublayers, one for the front and one for the back (I'm creating a "flip" effect). However, this code just sets the position and transform without animation. So I thought that maybe transform
doesn't support implicit animation, so I took that out and just tried setting the position, but that didn't animate either (and I know for sure that position
supports implicit animation).
Am I doing something wrong or does CATransformLayer
just not support implicit animation? The documentation does not say anything about it not supporting it, so I'm assuming it does.
EDIT: This is for M开发者_运维问答ac OS X, not iOS
I ended up just using explicit animation, but David Duncan's answer here seems like a step in the right direction for anyone else who comes across this issue.
Implicit animations are disabled for all layers associated with UIView
s. I have a much more detailed response on another question if you're curious as to the details. But in short, if you want animations on a layer associated with a view, you need to do them explicitly (i.e. attach CAAnimation
objects using -addAnimation:forKey:
).
Edit: It turns out this question is for OS X, and the CATransformLayer is actually a sublayer anyway. Please disregard this answer (though the linked answer is still useful for iOS).
Only the sublayers of a CATransformLayer
are rendered. So my guess is that its transform
property is never applied. Have you tried setting the sublayerTransform
property instead? It seems like that's what you're going for anyway.
If you add a layer and try to animate it in the same run loop, the animation won't happen - it'll occur instantly. You need to wrap adding the layer in a CATransaction. Afterwards, you can either implicitly or explicitly animate. For example, this should work:
[CATransaction begin];
[self.view.layer addSublayer:transformLayer];
[CATransaction commit];
// implicit animation will now occur because we're in the next run loop
transformLayer.transform = newTransform;
精彩评论