2010-11-24 112 views
1

請你能告訴我如何旋轉UIView(餅圖上),就好像它在一個樞軸上。只有用戶彈出視圖後纔會旋轉。旋轉樞軸上的UIView

回答

4

你會使用這樣的:

- (void)spin 
{ 
     CABasicAnimation *fullRotation; 
     fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
     fullRotation.fromValue = [NSNumber numberWithFloat:0]; 
     fullRotation.toValue = [NSNumber numberWithFloat:M_PI * 360/180.0]; 
     fullRotation.duration = 0.25; 
     fullRotation.repeatCount = 1; 
     [self.view.layer addAnimation:fullRotation forKey:@"360"]; 
} 

僅僅調用旋方法時要旋轉360度。根據需要調整以旋轉更多,更少,更快,更慢等。

編輯:應該注意,在上面的代碼中,view屬性是我們正在旋轉的屬性,以防它不明顯。因此,將self.view更改爲您想要旋轉的視圖。