如何禁用 UIView 动画块中嵌套的代码的动画?
有一个方法由第三方 API 在动画块内调用。在这种方法中,我应该构建一些子视图。但在这种情况下,我不希望在构造子视图时发生动画。
有没有办法说“[UIView dontAnimateFromHere] ... [UIView nowYouMayAnimateAgain]”?
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 animation to happen when constructing the subviews.
Is there a way of saying "[UIView dontAnimateFromHere] ... [UIView nowYouMayAnimateAgain]"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,确实有这样的方法。就像这样:
...这将禁用通过块触发的 UIView 动画和使用旧的开始/结束方法触发的动画。
也就是说,我假设您的第三方库是预编译的,否则您可以直接修改源代码:当然有可能它正在做一些奇怪的事情并以另一种方式进行动画处理,因此您的里程可能会因该解决方案而异。
这不会禁用动画块中所做的更改:它们会立即发生。否则,您将面临发生不好的事情的风险,因为您的第三方 API 会对哪些视图可能不正确做出假设。
Yes indeed, there is such a way. It's like this:
...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.
对于 iOS 7 及更高版本,有此 UIView 的 +performWithoutAnimation:。
请注意,
performWithoutAnimation
对于在动画块内立即执行更改非常有用,但它不会禁用嵌套块内进行的动画调用,因此使用它是为了方便,但它不那么强大作为原始答案的setAnimationsEnabled
。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 assetAnimationsEnabled
of the original answer.