iOS - UIView animateWithDuration 中的完成 block 被过早调用

标签 ios uiviewanimation

我正在尝试在选择表格 View 单元格时制作一些动画。出于某种原因,完成 block 被调用得太早了。即使将持续时间设置为 10 秒,完成 block 也会立即被调用。

[UIView animateWithDuration:10.0 animations:^{
    message.frame = newFrame;
} completion:^(BOOL finished) {
    NSLog(@"DONE???");
}];

有没有想过为什么会这样?谢谢。

最佳答案

来自UIView documentation :

completion

A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

这意味着不能保证代码只会在动画完成时执行。我建议您检查“完成”参数作为执行条件。

关于iOS - UIView animateWithDuration 中的完成 block 被过早调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14669601/

相关文章:

objective-c - 用于解析 html 的正则表达式;

iphone - 添加视网膜显示支持会导致 OpenGL ES 不绘制任何内容

java - IOS 收据验证 IllegalArgumentException

ios - 动画约束导致 subview 布局在屏幕上可见

ios - 改变标题时 UIButton 转到动画的起点

javascript - 使用 angularjs 在 iOS 上聚焦文本区域

iphone - 在分页 UIScrollView 中手势识别器的 sender.view 上的奇怪行为 UIView 动画

ios - 设置框架后 UIViewAnimation 反弹

ios - 模仿 UIAlertController 展示动画

iphone - 从 init 方法调用方法?