2012-04-17 127 views
0

我想創建兩種方法... StartSpin和StopSpin。在StartSpin中,我需要一個UIImageView旋轉360度並循環,直到我調用StopSpin。Monotouch:創建旋轉圖像?

這裏是我的StartSpin那麼遠,

private void StartSpin() {   
    UIView.Animate (
     1, 
     0, 
     UIViewAnimationOptions.Repeat, 
     () => { 
      CGAffineTransform t = CGAffineTransform.MakeIdentity(); 
      t.Translate(0, 0); 
      t.Rotate((float)(3.14)); 
      this._imageViewWait.Transform = t; 
     }, 
     () => {} 
    ); 
} 

這裏是我的兩個問題......

  1. 我如何讓它旋轉360度?

  2. 我應該在StopSpin方法中使用什麼命令來停止旋轉?

感謝

回答

0

爲了使圖像旋轉,你可以使用(轉動1度):

CGAffineTransform rotate = CGAffineTransformMakeRotation(1.0/180.0 * 3.14); 
[imageView setTransform:rotate]; 

爲了使圖像旋轉,只需創建一個定時器不斷調用此方法(並增加程度)。此外,如果你想繼續旋轉,創建一個布爾值來跟蹤跟蹤。

要停止旋轉,只需將布爾值更改爲false即可。然後,繼續更新,直到到達開始處(度數爲360或0)並且布爾值爲假。

如果你不想繼續旋轉,直至圖像恢復到原來的位置,只是消除&& degrees == 0

在代碼:

-(void)startSpinning { 
    degrees = 0; 
    continueSpinning = true; 
    [self continueSpinning]; 
} 

-(void)continueSpinning { 
    degrees = (degrees + 1) % 360; 

    CGAffineTransform rotate = CGAffineTransformMakeRotation(degrees/180.0 * 3.14); 
    [imageView setTransform:rotate]; 

    if(!continueSpinning && degrees == 0) return; 
    else [self performSelector:@selector(continueSpinning) withObject:nil afterDelay:0.1f]; 
} 

-(void)stopSpinning { 
    continueSpinning = false; 
}