首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >360度移动图像

360度移动图像
EN

Stack Overflow用户
提问于 2009-10-06 05:51:03
回答 3查看 1.1K关注 0票数 0

如何将图像从起点360度移动到终点?360度移动图像?

EN

回答 3

Stack Overflow用户

发布于 2009-10-06 05:55:55

可以按一定数量的弧度旋转视图,而不必将旋转拆分为多个部分,而不管它是小于完全旋转还是完全旋转的倍数。例如,下面的代码将每秒旋转视图一次,持续指定的秒数。您可以轻松地对其进行修改,以按一定数量的旋转或按一定数量的弧度旋转视图。

代码语言:javascript
复制
- (void) runSpinAnimationWithDuration:(CGFloat) duration;
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    [myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
票数 1
EN

Stack Overflow用户

发布于 2009-10-06 06:09:51

在任意轴上旋转360度会使视图保持不变。所以不要碰图像,你就可以走了!

票数 1
EN

Stack Overflow用户

发布于 2011-03-17 06:47:33

您也可以使用动画函数(CAValueFunction)来实现这一点:

代码语言:javascript
复制
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
rotationAnimation.duration = duration;
rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0];
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
rotationAnimation.valueFunction = [CAValueFunction functionWithName:kCAValueFunctionRotateZ];
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

[myView.layer addAnimation:rotationAnimation forKey:nil];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1523803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档