Spin UIImageView不断像3D一样

时间:2016-03-10 12:40:58

标签: ios objective-c uiimageview

我想像3D一样旋转图像,而不是像顺时针那样从上/下旋转。 我试过下面的代码翻转图像,但不是连续旋转。

UIImage *picture=[UIImage imageNamed:@"1.png"];
  flippedImage = [UIImage imageWithCGImage:picture.CGImage scale:picture.scale orientation:UIImageOrientationUpMirrored];
    imgV.image=flippedImage;

此代码顺时针旋转图像,但我想要3D风格。

CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 3.5f;
fullRotation.repeatCount = MAXFLOAT;

[imgV.layer addAnimation:fullRotation forKey:@"360"];

1 个答案:

答案 0 :(得分:0)

我必须说,你想要实现的效果并不是很清楚,但如果你的意思是翻页,我猜这个片段可能很有用。

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

它接近于3d动画,如果你想获得更多,你可以在另一层中托管它,并通过修改m34值来设置-sublayerTransform具有特定CATransform3D以提供想法透视。