誰能告訴我如何在圓周運動iphone的UIImageView旋轉
9
A
回答
2
如果你的意思是,旋轉圖像?「你怎麼做的圖像追隨圓形路徑」,那麼僞是:
image.x = circleCentre.x + cos(angle) * circleRadius;
image.y = circleCentre.y + sin(angle) * circleRadius;
angle += 5;
1
This question要求同樣的事情,儘管換言之。在這個問題中的答案以及this question應該提供一種方法來爲UIView(UIImageView僅僅是它的一個子類)創建一個關於360度或更多中心的動畫。
28
無論是小於完整旋轉還是多次旋轉,都可以將視圖旋轉一定數量的弧度,而無需將旋轉分割成幾部分。作爲一個例子,下面的代碼會在一個指定的秒數內旋轉一個視圖,每秒一次。您可以輕鬆修改它以旋轉一定數量的旋轉視圖,或旋轉一定數量的弧度。
- (void) runSpinAnimationWithDuration:(CGFloat) duration;
{
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 = 1.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
3
基於mahboudz的回答,您可以將其設置設定爲無限旋轉:
rotationAnimation.repeatCount = HUGE_VALF;
1
創建動畫
- (CABasicAnimation *)spinAnimationWithDuration:(CGFloat)duration clockwise:(BOOL)clockwise repeat:(BOOL)repeats
{
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
anim.toValue = clockwise ? @(M_PI * 2.0) : @(M_PI * -2.0);
anim.duration = duration;
anim.cumulative = YES;
anim.repeatCount = repeats ? CGFLOAT_MAX : 0;
return anim;
}
將它添加到一個視圖
CABasicAnimation *animation = [self spinAnimationWithDuration:1.0 clockwise:YES repeat:YES];
[self.spinningView.layer addAnimation:animation forKey:@"rotationAnimation"];
這個答案如何不同來自@ mahboudz的回答?如果大多數函數都返回對象,而不是僅僅操縱一些對象,那麼您將擁有更簡潔的代碼。
相關問題
- 1. 的UIImageView旋轉和縮放在iPhone SDK
- 2. 根據iPhone的方向旋轉UIImageView
- 3. 在UITableViewCell中旋轉UIImageView - iPhone SDK
- 4. iPhone:如何左右旋轉UIImageView?
- 5. 用觸摸手勢旋轉UIImageView - iphone dev
- 6. 如何旋轉UIImageView
- 7. UIImageView旋轉圖像
- 8. 用TapGesture旋轉UIImageView
- 9. 如何旋轉UIImageView?
- 10. UIImageView旋轉多少?
- 11. 連續旋轉UIImageView
- 12. uiimageview旋轉,不在中心旋轉
- 13. 旋轉uiimageview時的問題
- 14. 動畫旋轉的UIImageView
- 15. 旋轉的UIImageView 1度
- 16. 的UIImageView旋轉和調整
- 17. UIImageView旋轉我的UIImage
- 18. UIImageView上的旋轉動畫
- 19. 縮放和旋轉UIImageView
- 20. 旋轉UIImageView,然後縮放
- 21. 如何旋轉UIImage或UIImageView?
- 22. 背景UIImageView不旋轉
- 23. 移動和旋轉UIImageView
- 24. UIImageView不居中後旋轉
- 25. 在UIImageView中旋轉圖像
- 26. UIImageView旋轉問題iOS
- 27. 檢測iPhone旋轉旋轉?
- 28. 旋轉180度的的UIImageView和旋轉回來原路
- 29. 爲的UIImageView旋轉動畫旋轉別的
- 30. iPhone旋轉不會旋轉的UIWebView
也許你對旋轉和革命感到困惑。上述問題是關於革命的。 – Biranchi 2010-04-30 05:28:31