Ich entwickle eine Anwendung, in der ich möchte ein UIImage sollte in einem UIImageview 360 Grad, in 3 Dimensionen drehen. Ich habe viele Codes ausprobiert, aber der gesamte Code mit CAAnimation dreht das ganze Bild im Uhrzeigersinn oder dreht die gesamte Bildansicht um. Also, wie kann ich diese Art von Funktionalität entwickeln?Bild Drehen in der Bildansicht 360 Grad in 3D in iOS
1
A
Antwort
2
In Swift, können Sie den folgenden Code für unendliche Rotation verwenden: 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)
}
}
Stopping ist wie:
func stopRotatingView(view: UIView) {
if view.layer.animationForKey(kRotationAnimationKey) != nil {
view.layer.removeAnimationForKey(kRotationAnimationKey)
}
}
Objective C
dies gearbeitet perfekt für mich: iphone UIImageView Rotation
#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"];
}
Überprüfen Sie diese http://stackoverflow.com/questions/6531332/how-to-rotate-an-uiimageview-with-catransform3drotate-make-an-effect-like-door-o – kb920