2011-12-05 56 views
1

我有一個UIView對象。它在我改變全局變量角時旋轉。 我有一個函數,從它的超級視圖中刪除這個UIView並重畫它。 我已添加一個按鈕。當用戶按下這個按鈕時,我需要啓動一個動畫。 在每一步我都需要改變角度並調用我的重繪函數。所以如此效果我期望看到的是我的觀點在旋轉。 這裏是代碼:UIView animateWithDuration不起作用

-(IBAction)animate:(id)sender 
{ 
    NSLog(@"animate: called"); 
    [UIView animateWithDuration:0.7 
          delay:0.0 
         options: UIViewAnimationCurveEaseOut 
        animations:^{ 
        angle=angle+5.0; 
        if (angle>360) 
        { 
         angle=angle-360; 
        } 
        else if(angle<0) 
        { 
         angle=angle+360; 
        }; 

        NSLog(@"inner angle: %g", angle); 
        [self transform]; //this is my redraw function. it redraws my view depending on global variable value angle. 
       } 
       completion:NULL]; 
NSLog(@"finalAngle: %g", angle); 
} 

爲什麼這個動畫不能正常工作?

+0

我的NSLog輸出爲: 動畫:被稱爲 內角:5 變換:所謂 finalAngle:5 變換:所謂 – Oleg

+0

它看起來像在animateWithDuration塊只能1次。我在哪裏可以指出他在0.7秒內需要他工作多少次? – Oleg

+0

它動畫,但我的時候我稱之爲「動畫」我的視圖從0角度旋轉,但不是從先前的值(這是低5度) – Oleg

回答

1

的UIView動畫僅支持以下屬性

@property frame 
@property bounds 
@property center 
@property transform 
@property alpha 
@property backgroundColor 
@property contentStretch 

你必須有核心的動畫框架

+0

通過動畫變換屬性,他可以做旋轉......我錯了嗎? –

0

執行動畫可以動畫變換屬性。但是,使用transform屬性執行旋轉比使用CA Framework更復雜。我發現這個職位有幫助:UIView Infinite 360 degree rotation animation?

+0

歡迎來到SO!最好是你包含來自鏈接源的更多細節,而不僅僅是一個鏈接。 – Emil

相關問題