使用 Objective-C 块的 UIView 动画
我一直在尝试两种不同的 UIView 动画制作方法:开始/提交和块。
我注意到 beginAnimations:context:
/ commitAnimations
的处理方式很好地异步,在动画运行时保持 UI 自由。
但是,我还注意到 animateWithDuration:animations:completion 方式似乎会阻塞 UI,使其在动画运行时无响应。
我认为使用块的要点之一是轻松实现异步执行。为什么 UIView
动画的 block 变体会阻塞 UI,而 begin/commit 变体却不会?
编辑:
我的问题最初假设块动画是同步操作并阻塞了 UI。从杰夫·凯利的回答中可以看出,事实并非如此。我最初的假设是错误的,块动画不同步。详情请参阅杰夫的回答。
I have been playing around with the two different ways of doing UIView
animations: begin/commit and Blocks.
I have noticed that the beginAnimations:context:
/ commitAnimations
way of doing things is nicely asynchronous, keeping the UI free while the animation is running.
However, I also noticed that the animateWithDuration:animations:completion
way seems to block the UI, making it unresponsive while the animation is running.
I thought one of the main points of using blocks was to achieve asynchronous execution easily. Why does the blocks variant of the UIView
animarions block the UI while the begin/commit variant does not?
Edit:
My question originally assumed that the blocks animation was a synchronous operation and blocked the UI. As it transpired from Jeff Kelly's answer, that this isn't the case. My original assumption was incorrect, the blocks animation is not synchronous. See Jeff's answer for the details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的
UIView
类方法正确吗?如果您使用+animateWithDuration:delay:options:animations:completion:,您可以指定选项的位掩码。可能的选项之一是 UIViewAnimationOptionAllowUserInteraction,这听起来正是您想要的。Are you using the right
UIView
class method? If you use+animateWithDuration:delay:options:animations:completion:
, you can specify a bitmask of options. One of the possible options isUIViewAnimationOptionAllowUserInteraction
, which sounds like just what you want.