gpt4 book ai didi

ios - 图像在 iOS 中的 3D ImageView 中旋转 360 度

转载 作者:行者123 更新时间:2023-11-28 21:23:52 25 4
gpt4 key购买 nike

我正在开发一个应用程序,其中我希望 UIImage 应该在 UIImageview 中以 3 维旋转 360 度。我尝试了很多代码,但所有带有 CAAnimation 的代码都会顺时针旋转整个图像或翻转整个 ImageView 。那么,我该如何开发此类功能?

最佳答案

在Swift中,可以使用如下代码实现无限旋转: swift -

let kRotationAnimationKey = "com.myapplication.rotationanimationkey" // Any key

func rotateView(view: UIView, duration: Double = 1) {
if view.layer.animationForKey(kRotationAnimationKey) == nil {
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation")

rotationAnimation.fromValue = 0.0
rotationAnimation.toValue = Float(M_PI * 2.0)
rotationAnimation.duration = duration
rotationAnimation.repeatCount = Float.infinity

view.layer.addAnimation(rotationAnimation, forKey: kRotationAnimationKey)
}
}

停止就像:

func stopRotatingView(view: UIView) {
if view.layer.animationForKey(kRotationAnimationKey) != nil {
view.layer.removeAnimationForKey(kRotationAnimationKey)
}
}

objective-c

这对我来说非常有效:iphone UIImageView 旋转

#import <QuartzCore/QuartzCore.h>

- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat;
{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = repeat;

[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

关于ios - 图像在 iOS 中的 3D ImageView 中旋转 360 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38800922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com