-(void) startAnimation
{
[UIView animateWithDuration:1.5 animations:^{
CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:(2*M_PI)];
fullRotation.duration =1.0f;
fullRotation.repeatCount = MAXFLOAT;
// add animation in your view
[_imageView1.layer addAnimation:fullRotation forKey:@"3601"];
[_imageView2.layer addAnimation:fullRotation forKey:@"3602"];
}];
}
-(void)endAnimation
{
[_imageView1.layer removeAnimationForKey:@"3601"];
[_imageView2.layer removeAnimationForKey:@"3602"];
NSLog(@"停止");
}
或者:
-(void) startAnimation
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.01];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(endAnimation)];
_imageView1.transform = CGAffineTransformMakeRotation(angle * (M_PI / 180.0f));
_imageView2.transform = CGAffineTransformMakeRotation(angle * (M_PI / 180.0f));
[UIView commitAnimations];
}
-(void)endAnimation
{
angle += 10;
[self startAnimation];
}
或者:
timer=[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(transformAction) userInfo:nil repeats:YES];
-(void)transformAction {
angle +=5;
CGAffineTransform endAngle = CGAffineTransformMakeRotation(angle * (M_PI / 180.0f));
_imageView1.transform = endAngle;
_imageView2.transform=endAngle;
}
(iOS开发)图片等实现360°旋转
最新推荐文章于 2022-04-25 17:55:04 发布