ios - 如何实现图片的3D旋转,而且是不停旋转?
伊谢尔伦
伊谢尔伦 2017-04-17 16:11:42
[iOS讨论组]

我的代码是这样的:

//  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伐。

全部回复(2)
怪我咯
[UIView animateWithDuration:3
                      delay:0
                    options:UIViewAnimationOptionRepeat
                 animations:^{

                 }
                 completion:^(BOOL finished) {

                 }];
阿神

LZ的代码,并不是按照Y找转,Y,Z同时都会动,按Y轴循环转动,有以下两种方法可供参考,推荐第一种方法,过渡更平滑,自然.
方法一:

    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"];

方法二:

[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);
                 }];
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号