使用 Objective-C 块的 UIView 动画

发布于 2024-10-18 14:05:58 字数 442 浏览 2 评论 0原文

我一直在尝试两种不同的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2024-10-25 14:05:58

您使用的 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 is UIViewAnimationOptionAllowUserInteraction, which sounds like just what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文