在iOS4 +中显式禁用UIViewanimation

我一直在阅读,苹果build议使用基于块的animation,而不是CATransaction

之前,我正在使用此代码来禁用animation:

[CATransaction begin]; [CATransaction setDisableActions: YES]; // !!! resize [CATransaction commit]; 

有没有新的推荐方法来做到这一点,或者这还可以吗?

 [UIView setAnimationsEnabled:NO]; //animate here [UIView setAnimationsEnabled:YES]; 

对于iOS 7及以上版本,现在可以通过以下方式完成:

 [UIView performWithoutAnimation:^{ // Changes we don't want animated here view.alpha = 0.0; }]; 

对于MonoTouch(C#)用户,这里是一个辅助类:

 public class UIViewAnimations : IDisposable { public UIViewAnimations(bool enabled) { _wasEnabled = UIView.AnimationsEnabled; UIView.AnimationsEnabled = enabled; } public void Dispose() { UIView.AnimationsEnabled = _wasEnabled; } bool _wasEnabled; } 

例:

 using (new UIViewAnimations(false)) imageView.Frame = GetImageFrame(); 
Interesting Posts