使用Objective-C块的UIView动画

时间:2022-04-25 20:01:07

I have been playing around with the two different ways of doing UIView animations: begin/commit and Blocks.

我一直在玩两种不同的UIView动画方式:begin / commit和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.

我注意到beginAnimations:context:/ commitAnimations的处理方式非常异步,在动画运行时保持UI*。

However, I also noticed that the animateWithDuration:animations:completion way seems to block the UI, making it unresponsive while the animation is running.

但是,我也注意到animateWithDuration:动画:完成方式似乎阻止了UI,使其在动画运行时没有响应。

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?

我认为使用块的一个要点是轻松实现异步执行。为什么UIView动画的块变体会阻止UI,而begin / commit变体却没有?

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.

我的问题最初假设块动画是同步操作并阻止了UI。从Jeff Kelly的回答中可以看出,事实并非如此。我原来的假设不正确,块动画不同步。有关详细信息,请参阅Jeff的答案。

1 个解决方案

#1


16  

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.

您使用正确的UIView类方法吗?如果使用+ animateWithDuration:delay:options:animations:completion:,则可以指定选项的位掩码。其中一个可能的选项是UIViewAnimationOptionAllowUserInteraction,听起来就像你想要的那样。

#1


16  

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.

您使用正确的UIView类方法吗?如果使用+ animateWithDuration:delay:options:animations:completion:,则可以指定选项的位掩码。其中一个可能的选项是UIViewAnimationOptionAllowUserInteraction,听起来就像你想要的那样。