Apple が CATransaction の代わりにブロックベースのアニメーションを使用することを推奨していることを読んでいます。
以前は、次のコードを使用してアニメーションを無効にしていました。
[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;
}];
スイフト 3+
UIView.performWithoutAnimation {
// Update UI that you don't want to animate
}
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();