我在 tabbarviewcontroller 的第一个 View Controller 上有这个动画
- (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];
}
它工作得很好,但是当我从标签栏更改 viewcontroller 并返回到第一个 viewcontroller 动画停止时。
有一个类似的线程iOS UIView Animation Issue但没有任何解释
最佳答案
试试这个:
- (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 的动画——没有任何变化。
关于iphone - 更改 VIewControllers 停止动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10255304/