ios - 如何实现图片的3D旋转,而且是不停旋转?
伊谢尔伦
伊谢尔伦 2017-04-17 16:11:42
0
2
634

我的代码是这样的:

//  ViewController.m
//  核心动画
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [UIView  animateWithDuration:3 animations:^{
self.imageView.layer.transform=CATransform3DMakeRotation(M_PI, 0, 1,1);
    }]; 
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end

但是这样做旋转了一次就不在旋转了。请问如何实现不停的旋转呢?(按照Y轴)

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
刘奇
[UIView animateWithDuration:3
                      delay:0
                    options:UIViewAnimationOptionRepeat
                 animations:^{

                 }
                 completion:^(BOOL finished) {

                 }];
阿神

LZ’s code does not rotate according to Y. Y and Z will move at the same time. It rotates cyclically according to the Y axis. There are two methods for reference. The first method is recommended because the transition is smoother and more natural.
Method 1:

    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 3;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = MAXFLOAT;
    
    [self.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

Method 2:

[UIView animateWithDuration:3
                      delay:0
                    options:UIViewAnimationOptionRepeat
                 animations:^{
                     self.imageView.layer.transform=CATransform3DMakeRotation(M_PI, 0, 1, 0);
                 }
                 completion:^(BOOL finished) {
                     self.imageView.layer.transform=CATransform3DMakeRotation(M_PI, 0, 1, 0);
                 }];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template