用基础动画实现iOS控件循环旋转
- (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; }
“人生苦短,不要把时间浪费在犹豫不决上,喜欢的东西就去买,喜欢的人就去追。”