2013-10-25 56 views
0

我遇到問題。如何減慢物體的旋轉?

我有這樣的代碼:

if(CGRectContainsPoint(compassTarcsa.frame, curLoc)) 
{ 
    compassTarcsaTouch = YES; 

    float fromAngle = atan2(compassFirstLoc.y-compassTarcsa.center.y,compassFirstLoc.x-compassTarcsa.center.x); 
    float toAngle = atan2(curLoc.y-compassTarcsa.center.y,curLoc.x-compassTarcsa.center.x); 

    newAngle = (angle + (toAngle - fromAngle)); 
    iranyFok = (newAngle/(M_PI/180.0f)) ; 


    if (iranyFok < 0.0f) { 
     iranyFok += 360.0f; 
    } 

    iranyFok = 360-(fmodf((360 + iranyFok), 360)); 

    CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(- iranyFok)); 

    compassTarcsa.transform = cgaRotate; 
    repcsi.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(iranyFok)); 

這種旋轉從0指南針到360度,但轉速快給我......

有人可以幫助我瞭解如何減緩這旋轉?

THX,

亞歷

回答

0

試試這個:

[UIView animateWithDuration:2.0 delay:0 options: UIViewAnimationOptionCurveEaseInOut 
    animations:^(void){ 
      compassTarcsa.transform = cgaRotate; 
    } completion:NULL 
]; 

這將你包裹在動畫中,使您可以控制旋轉時間變換旋轉。