ios – 使用CABasicAnimation多次旋转UIImageView

ios – 使用CABasicAnimation多次旋转UIImageView,第1张

概述我正在使用CABasicAnimation顺时针旋转UI ImageView 90度,但是在最初90度旋转之后,我需要将其从其位置再旋转90度. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];animation.duration = 10;animati 我正在使用CABasicAnimation顺时针旋转UI ImageVIEw 90度,但是在最初90度旋转之后,我需要将其从其位置再旋转90度.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];animation.duration = 10;animation.additive = YES;animation.removedOnCompletion = NO;animation.fillMode = kCAFillModeForwards;animation.fromValue = [NSNumber numberWithfloat:degrees_TO_radians(0)];animation.tovalue = [NSNumber numberWithfloat:degrees_TO_radians(90)];[_myvIEw.layer addAnimation:animation forKey:@"90rotation"];

使用上面的代码最初起作用,图像保持在90度角.如果我再次打电话给它,使其旋转90度,则动画将通过跳回到0并旋转90度,而不是90到180度.

我的印象是animation.additive = YES;将会使进一步的动画以当前状态为起点.

有任何想法吗?

解决方法 通过角度增量值查看我的代码
static int imgAngle=0;- (voID)doAnimation{  CABasicAnimation *animation = [CABasicAnimation   animationWithKeyPath:@"transform.rotation.z"];   animation.duration = 5;  animation.additive = YES;  animation.removedOnCompletion = NO;  animation.fillMode = kCAFillModeForwards;  animation.fromValue = [NSNumber numberWithfloat:degrees_TO_radians(imgAngle)];  animation.tovalue = [NSNumber numberWithfloat:degrees_TO_radians(imgAngle+90)]; [self.imgVIEw.layer addAnimation:animation forKey:@"90rotation"];  imgAngle+=90;  if (imgAngle>360) {      imgAngle = 0;  }}

以上代码只是想法.它没有测试

总结

以上是内存溢出为你收集整理的ios – 使用CABasicAnimation多次旋转UIImageView全部内容,希望文章能够帮你解决ios – 使用CABasicAnimation多次旋转UIImageView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1108851.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存