如何实现图片的3D旋转,而且是不停旋转?

我的代码是这样的:
//ViewController.m
//核心动画
#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIImageView*imageView;
@end
@implementationViewController
-(void)viewDidLoad{
[superviewDidLoad];
}
-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event{
[UIViewanimateWithDuration:3animations:^{
self.imageView.layer.transform=CATransform3DMakeRotation(M_PI,0,1,1);
}];
}
-(void)didReceiveMemoryWarning{
[superdidReceiveMemoryWarning];
}
@end
但是这样做旋转了一次就不在旋转了。请问如何实现不停的旋转呢?(按照Y轴)
牛魔王的故事
浏览 665回答 2
2回答

慕哥6287543

[UIViewanimateWithDuration:3delay:0options:UIViewAnimationOptionRepeatanimations:^{}completion:^(BOOLfinished){}];

尚方宝剑之说

LZ的代码,并不是按照Y找转,Y,Z同时都会动,按Y轴循环转动,有以下两种方法可供参考,推荐第一种方法,过渡更平滑,自然.方法一:CABasicAnimation*rotationAnimation;rotationAnimation=[CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];rotationAnimation.toValue=[NSNumbernumberWithFloat:M_PI*2.0];rotationAnimation.duration=3;rotationAnimation.cumulative=YES;rotationAnimation.repeatCount=MAXFLOAT;[self.imageView.layeraddAnimation:rotationAnimationforKey:@"rotationAnimation"];方法二:[UIViewanimateWithDuration:3delay:0options:UIViewAnimationOptionRepeatanimations:^{self.imageView.layer.transform=CATransform3DMakeRotation(M_PI,0,1,0);}completion:^(BOOLfinished){self.imageView.layer.transform=CATransform3DMakeRotation(M_PI,0,1,0);}];
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript