2012-11-22 26 views
10

在使用核心情節我添加了對於給定的代碼動畫發展餅圖如何避免這種程度的弧度誤差?

CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
    CATransform3D transform = CATransform3DMakeRotation(DegreesToRadians(360), 0, 0, 1); 
    rotation.toValue = [NSValue valueWithCATransform3D:transform]; 
    rotation.duration = 10.0f; 
    [pieChart addAnimation:rotation forKey:@"rotation"];  

此代碼提供了以下錯誤的語義問題:

Implicit declaration of function 'DegreesToRadians' is invalid in C99 

我能爲避免這種情況怎麼辦?

而且還運行時它提供了以下錯誤:

Apple_o Linker id error "_DegreesToRadians", referenced from: 

感謝和問候

維賈雅庫馬爾

在Rhytha

iOS開發

https://rhytha.com/

回答

22

只要定義一個宏像寫這樣的代碼:

#define DEGREES_RADIANS(angle) ((angle)/180.0 * M_PI) 

,改變你方法等:

CATransform3D transform = CATransform3DMakeRotation(DEGREES_RADIANS(360), 0, 0, 1); 
+0

感謝ü非常@MidhunMp – Vijay

+0

@VijayakumarNL:愉快:) –

0
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0/M_PI)) 

在您.m文件的頂部,你要轉換

讓我知道是否是工作或沒有

0

對於簡單的角度,只需使用弧度:

Transform3D transform = CATransform3DMakeRotation(2 * M_PI, 0, 0, 1); 

典型角度的快速列表:

Degrees | Code 
--------+--------- 
360  | 2 * M_PI 
180  | M_PI 
90  | M_PI_2 
45  | M_PI_4