CABasicAnimation - 视图应该定位在最后一帧
CABasicAnimation - view should position on the last frame
你好,我想做一个 CABasicAnimation 旋转,我的视图旋转 440 度。在动画之后我不想将视图重置到旧位置。它应该与动画最后一帧的位置相同。
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotate.toValue = [NSNumber numberWithFloat:degrees / 180.0 * M_PI];
rotate.duration = 4.4;
[rotate setFillMode:kCAFillModeForwards];
UIView *animationView = [self getBGContainerViewForSender:sender];
[animationView.layer addAnimation:rotate forKey:@"myRotationAnimation"];</i>
谁能告诉我如何在最后一帧定位视图?
在启动动画之前进行如下交易:
[CATransaction begin];
[CATransaction setValue:kCFBooleanTrue forKey:kCATransactionDisableActions];
CATransform3D current = animationView.layer.transform;
animationView.layer.transform = CATransform3DRotate(current, numberWithFloat:degrees / 180.0 * M_PI, 0, 1.0, 0);
[CATransaction commit];
/* YOUR ORIGINAL CODE COMES HERE*/
创建动画并将其添加到图层时,您并没有更改对象中的任何值。所以在你的情况下,animationView 的变换 属性 不会改变。因此,当动画结束时,视图将回到原来的位置。要解决这个问题,您必须做两件事:
在添加动画之前,将视图层的变换 属性 设置为动画完成后所需的值。但是,这会给层添加一个隐式动画,所以你需要杀死隐式动画。为此:
添加动画方法中forKey:
的值必须是动画的名称,本例为"transform"。此名称将用您的显式动画替换转换的隐式动画。
所以添加:
animationView.layer.transform = CA3DTransformMakeRotate(....);
并将添加动画调用更改为
[animationView.layer addAnimation:rotate
forKey:@"transform"];
这在 WWDC 2010 中解释,核心动画实践第 1 部分,大约 39:20。
你好,我想做一个 CABasicAnimation 旋转,我的视图旋转 440 度。在动画之后我不想将视图重置到旧位置。它应该与动画最后一帧的位置相同。
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotate.toValue = [NSNumber numberWithFloat:degrees / 180.0 * M_PI];
rotate.duration = 4.4;
[rotate setFillMode:kCAFillModeForwards];
UIView *animationView = [self getBGContainerViewForSender:sender];
[animationView.layer addAnimation:rotate forKey:@"myRotationAnimation"];</i>
谁能告诉我如何在最后一帧定位视图?
在启动动画之前进行如下交易:
[CATransaction begin];
[CATransaction setValue:kCFBooleanTrue forKey:kCATransactionDisableActions];
CATransform3D current = animationView.layer.transform;
animationView.layer.transform = CATransform3DRotate(current, numberWithFloat:degrees / 180.0 * M_PI, 0, 1.0, 0);
[CATransaction commit];
/* YOUR ORIGINAL CODE COMES HERE*/
创建动画并将其添加到图层时,您并没有更改对象中的任何值。所以在你的情况下,animationView 的变换 属性 不会改变。因此,当动画结束时,视图将回到原来的位置。要解决这个问题,您必须做两件事:
在添加动画之前,将视图层的变换 属性 设置为动画完成后所需的值。但是,这会给层添加一个隐式动画,所以你需要杀死隐式动画。为此:
添加动画方法中
forKey:
的值必须是动画的名称,本例为"transform"。此名称将用您的显式动画替换转换的隐式动画。
所以添加:
animationView.layer.transform = CA3DTransformMakeRotate(....);
并将添加动画调用更改为
[animationView.layer addAnimation:rotate forKey:@"transform"];
这在 WWDC 2010 中解释,核心动画实践第 1 部分,大约 39:20。