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

用基础动画实现iOS控件循环旋转

2015-12-09 13:48 656 查看
- (void)viewDidLoad {
[super viewDidLoad];
UIButton* ag=[[UIButton alloc]initWithFrame:CGRectMake(screenWidth/2-75, 174, 150, 150)];
UIImage* img=[UIImage imageNamed:@"m_01"];
[ag setImage:img forState:UIControlStateNormal];
ag.backgroundColor=[UIColor redColor];
[self rotate360DegreeWithButton:ag];
[self.view addSubview:ag];
}

- (UIButton*)rotate360DegreeWithButton:(UIButton*)button
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.toValue = [NSNumber numberWithFloat:M_PI];
animation.duration = 10;
//旋转效果累计 先转180度 接着再旋转180度 从而实现360旋转
animation.cumulative = YES;
animation.repeatCount = 1000;
[button.layer addAnimation:animation forKey:@"transform.rotation.z"];
return button;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: