2012-04-21 119 views
2

我有一個tabbarviewcontroller更改VIewControllers停止動畫

- (void)viewDidAppear:(BOOL)animated 
{ 
    [UIView animateWithDuration:4.0 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{ 
     CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI); 
     self.rotatingImage.transform = transform; 
    } completion:NULL]; 
} 

它工作得很好,但是當我從使用TabBar改變視圖 - 控制並返回到第一的ViewController動畫停止的第一個視圖控制器此動畫。

有一個類似的線程iOS UIView Animation Issue但沒有任何一種解釋

回答

5

試試這個:

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    self.rotatingImage.transform = CGAffineTransformIdentity; 
    [UIView animateWithDuration:4.0 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{ 
     CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI); 
     self.rotatingImage.transform = transform; 
    } completion:NULL]; 
} 

解釋很簡單...當動畫代碼再次被觸發時,UIImageView的轉換已經等於動畫的最終轉換。這與UIImageView的alpha從1.0到1.0的動畫相似 - 沒有任何變化。

1

使用下面的代碼,並享受...

self.animationyourImageView.transform = CGAffineTransformIdentity; 

這將重置變換...

希望這可以幫到你..