2014-11-21 110 views
1

我使用這個代碼:如何在按下另一個按鈕時不斷旋轉按鈕45度?

[UIView animateWithDuration:ANIMATION_DURATION_SLOW 
         delay:0 
    usingSpringWithDamping:0.4 
     initialSpringVelocity:5.0 
        options:0 
       animations:^{ 

        _button.transform = CGAffineTransformMakeRotation(-M_PI_4); 
       } 
       completion:nil]; 

但是,該按鈕只轉動的第一次。無論我多次調用此方法,它都不會再次旋轉。

回答

3

設置旋轉變換不會添加到上一個變換中,它將替換它,因此您需要記住最後一次敲擊過程中的位置。一個快速的方法來做到這一點是一個靜態變量。

static tapCount = 0; 
tapCount++; 

[UIView animateWithDuration:ANIMATION_DURATION_SLOW 
        delay:0 
usingSpringWithDamping:0.4 
    initialSpringVelocity:5.0 
       options:0 
      animations:^{ 

       _button.transform = CGAffineTransformMakeRotation(-M_PI_4 * tapCount); 
      } 
      completion:nil]; 
1

這是因爲你需要改變角度。 考慮:

-(CGFloat)angle{ 
    if (!_angle) { 
     _angle = -M_PI_4; 
    } 

    _angle += -M_PI_4; 

return _angle; 
} 
相關問題