开发者

How to disable animation for code nested in a UIView animation block?

There's a method which is called inside an animation block by a third party API. In that method I'm supposed to build some subviews. But in this case I don't want animati开发者_开发技巧on to happen when constructing the subviews.

Is there a way of saying "[UIView dontAnimateFromHere] ... [UIView nowYouMayAnimateAgain]"?


Yes indeed, there is such a way. It's like this:

[UIView setAnimationsEnabled:NO];
// Animations happen here
[UIView setAnimationsEnabled:YES];

...this will disable both UIView animations triggered via blocks and animations triggered using the old begin/end methods.

That said, I'm assuming your third party library is pre-compiled otherwise you could modify the source directly: it is of course possible it's doing something weird and animating in another way, so your mileage may vary with this solution.

This won't disable the changes being made in the animation blocks: they'll simple happen immediately. Otherwise you'd risk bad things happening since your third party API would be making assumptions about where views might be that weren't true.


For iOS 7 and later, there is this UIView's +performWithoutAnimation:.

Note that performWithoutAnimation is useful for immediately executing a change while you are within an animation block, but it will not disable animation calls made within the nested block, so use it for convenience, but it is not as robust as setAnimationsEnabled of the original answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜