我试图通过使其从屏幕中心出现,同时将其增大到其全部大小,同时还在3D中围绕x轴旋转来呈现视图方式。当我创建视图时,我会对其应用一个转换以确保它缩小并旋转以启动(它实在太小而实际上不可见),然后我尝试使用如下的CATransform3D:如何在单个动画中缩放和旋转视图
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];
CATransform3D transform = CATransform3DRotate(view.layer.transform, M_PI, 1.0, 0, 0);
transform = CATransform3DScale(transform, 1000, 1000, 1000);
transform.m34 = 1.0/10000;
[anim setToValue:[NSValue valueWithCATransform3D:transform]];
[anim setDuration:0.75f];
anim.removedOnCompletion = NO;
anim.delegate = self;
[view.layer addAnimation:anim forKey:@"grow"];
然而,该动画不会改变实际转换层的,所以我也这样做:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
view.layer.transform = CATransform3DIdentity;
[view.layer removeAllAnimations];
}
设置一旦动画停止变换。然而,这有时会导致动画结束时出现明显的闪烁。我相信这是因为动画将原始变换放回动画阶段的末尾,并且在animationDidStop例程被调用之前发生。有一个更好的方法吗?
编辑:将它纳入一个UIView动画作品的这种方式,您可以直接设置变换:
view.layer.transform = CATransform3DScale(CATransform3DIdentity, 0.001, 0.001, 0.001);
view.layer.transform = CATransform3DRotate(view.layer.transform, M_PI, 1.0, 0.0, 0.0);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
CATransform3D transform = CATransform3DRotate(view.layer.transform, M_PI, 1.0, 0, 0);
transform = CATransform3DScale(rotationTransform, 1000, 1000, 1000);
transform.m34 = 1.0/-500;
view.layer.transform = transform;
[UIView commitAnimations];
不过,我还是想回答我的原始查询,至于如何达到同样的成功地使用CAAnimation,因为它为动画提供了更大的灵活性。
编辑2:它似乎是我原来的问题(如何解决与CAAnimation问题)的答案实际上是非常简单的。为了保持最终状态(和消除闪烁),我只需要添加以下行:
anim.fillMode = kCAFillModeForwards;
不,它设置为YES层上进行动画。 – bellissimo 2012-02-18 15:13:38
不幸的是,它没有任何区别。 – bellissimo 2012-02-18 15:30:42