您的位置:首页 > 移动开发 > IOS开发

iOS 旋转动画(图片360°旋转)关键代码

2015-12-03 14:03 435 查看
开发项目过程中,经常会做一些动画,比如进入某些页面需要让一个view进行360°旋转等等。结合网友们的经验,觉得下面的这些代码用起来还是比较方便的,就总结一下,方便下次使用。

创建一个UIImageView,并添加图片。

view1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 380, 380)];
view1.image=[UIImage imageNamed:@"八卦"];
view1.center=self.view.center;
view1.alpha=1;

[self.view addSubview:view1];


添加动画:

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
rotationAnimation.duration = 20;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 99999;//重复次数

[view1.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];


旋转效果如下图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: