1
我正在開發一個應用程序,其中我想UIImage應該在UIImageView 360度,3維中旋轉。 我已經嘗試了許多代碼,但CAAnimation的所有代碼順時針旋轉整個圖像或翻轉整個圖像視圖。 那麼,我該如何開發這種類型的功能呢?圖像在圖像視圖中旋轉360度在iOS中的3D度
我正在開發一個應用程序,其中我想UIImage應該在UIImageView 360度,3維中旋轉。 我已經嘗試了許多代碼,但CAAnimation的所有代碼順時針旋轉整個圖像或翻轉整個圖像視圖。 那麼,我該如何開發這種類型的功能呢?圖像在圖像視圖中旋轉360度在iOS中的3D度
在斯威夫特,你可以使用無限旋轉下面的代碼: 斯威夫特 -
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)
}
}
目標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"];
}
檢查此問題http://stackoverflow.com/questions/6531332/how-to-rotate-an-uiimageview-with-catransform3drotate-make-an-effect-like-door-o – kb920