2017-04-20 42 views
0

我想做一個類似於遊戲aa的演示。所以我需要獲得關於視圖旋轉的實時角度。下面的代碼纔可以得到最終的天使:如何獲取UIView實例旋轉角度,當它處於旋轉動畫狀態?

CGFloat rotationAngle = atan2f(_view.transform.b, _view.transform.a); 
CGFloat degreeAngle = rotationAngle * (180/M_PI); 

在我的腦海裏,如果我能在中央視圖中知道點插管的座標是旋轉的,我可能完成這個演示。例如,這一點可以使這樣的:

enter image description here

所以我想知道如何旋轉當前的觀點得到許多是度,或其它方式如何實現遊戲AA。

+0

halfer,感謝您關注我的問題edtion!我是使用stackoverflow的新手,我不知道有些問題需要注意。非常感謝您的幫助! – ZeroOnet

回答

0

經過一段時間的測試,這些代碼可以解決這個問題:

- (CGFloat)transformAngleWithRotationDirection:(BOOL)clockwise { 
    return clockwise ? [self transformRotationAngle] : 2.0f * M_PI - [self transformRotationAngle]; 
} 

- (CGFloat)transformRotationAngle { 
    CGFloat degreeAngle = - atan2f(self.presentationLayer.transform.m21, self.presentationLayer.transform.m22); 

    if (degreeAngle < 0.0f) { 
     degreeAngle += (2.0f * M_PI); 
    } 

    return degreeAngle; 
}