[英]How do I chain scale animations with an iPhone UIImageView?
我正在尝试缩小图像,更改图像,然后将其放大。
CABasicAnimation* shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrink.toValue = [NSNumber numberWithDouble:0];
shrink.duration = 1;
shrink.delegate = self;
[myImageView.layer addAnimation:shrink forKey:@"shrink"];
进行收缩,然后当它完成时,我更改图像,并开始增长:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
myImageView.image = [images objectAtIndex:image];
CABasicAnimation* grow = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
grow.toValue = CGAffineTransformMakeScale(1,1);
grow.delegate = self;
grow.duration = 1;
[myImageView.layer addAnimation:grow forKey:@"grow"];
}
这在模拟器上效果很好,但在设备上,当收缩完成时,我得到一个全尺寸的旧图像 flash,然后从新图像开始生长 animation。
知道如何摆脱 flash 吗?
(我尝试过“removedOnCompletion = NO;”并尝试将 affineTransform 设置为第一次完成后按比例缩小的大小,但运气不佳。)
任何提示表示赞赏。
KB
编辑:
优秀:设置以下内容:
shrink.fillMode = kCAFillModeForwards;
shrink.removedOnCompletion = NO;
去掉了闪退。 谢谢,本!
尝试将动画的fillMode
设置为kCAFillModeForwards
。 这应该使项目保持在 animation 的末尾,而不是之前。
当我尝试在 animationDidStop 方法中创建另一个 CAAnimation 时,我遇到了同样的问题。 我建议使用 CAKeyframeAnimation。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.