2009-10-10 188 views
0

任何有關如何順時針/逆時針旋轉圖像的想法。順時針/逆時針旋轉圖像

+0

您需要提供更多信息。你有沒有工作的代碼,或者你在尋找從哪裏開始的想法? – ChrisF 2009-10-10 11:51:29

回答

0

你會想爲此使用CoreAnimation;基本上,您需要將動畫應用於圖像視圖的transform屬性。 Apple的開發者頁面上有大量的samples,顯示了這個變化。

4
#import <QuartzCore/QuartzCore.h> 

[UIView beginAnimations:@"RotationAnimation" context:nil]; 

CABasicAnimation *fullRotationAnimation; 
fullRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
fullRotationAnimation .fromValue = [NSNumber numberWithFloat:0]; 
fullRotationAnimation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)]; 
fullRotationAnimation.duration = 2;   // speed for the rotation. Smaller number is faster 
fullRotationAnimation.repeatCount = 1e100f; // number of times to spin. 1 = once 
[myImage.layer addAnimation:fullRotationAnimation forKey:@"360"]; 

[UIView commitAnimations]; 
+2

實際上,我不相信UIView的開始/提交動畫塊在這裏是必要的,因爲你明確地爲視圖的層設置了動畫。您可能還想使用「transform.rotation.z」作爲動畫的關鍵路徑,以清楚地指定旋轉的軸。 – 2009-10-10 23:24:35

0

這可能是已故的回答你的問題,但它會幫助別人..
通過使用CGAffineTransformMakeRotation我們可以能夠將圖像旋轉

旋轉逆時針方向的圖像

-(void)rotate 
    { 
     x++; 
     CGAffineTransform transform = CGAffineTransformMakeRotation(x); 
     imageView.transform = transform; 
     [self performSelector:@selector(rotate) withObject:self afterDelay:0.1]; 

    } 

對於順時針方向使用x--;