自定義一個方法rotate360OfMyImage
-(void)rotate360OfMyImage{
[self.view addSubview:_myImageView];//添加子視圖
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.delegate = self;
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI/2, 0, 0, 1.0)];//圖片順時針旋轉
animation.duration = 10; //執行時間
animation.cumulative = YES;//累積效果,有了它,才可以使圖片先旋轉180,再旋轉360
animation.repeatCount = 10;//執行次數
[_myImageView.layer addAnimation:animation forKey:@"animation"];
}
然后在- (void)viewDidLoad調用就行了
當然,你的先有張圖片:
NSString *imageP = @"Q.jpg";
self.myImageView.image = [UIImage imageNamed:imageP];//這里是利用storyboard拖拽方式確定的圖片位置
補充:
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0, 0, 1.0)圖片逆時針旋轉
animation.autoreverses=YES;//是否自動重復(如果有這行代碼,則會一直重復0-180,再從180-0的動畫效果,也就是說圖片旋轉了180,就會自動轉回來)
PS:小白繼續加油中,也希望看到的小伙伴們指出不足