【问题标题】:Understanding ios UIView animation block and dispatch_async(dispatch_get_main_queue) block理解 ios UIView 动画块和 dispatch_async(dispatch_get_main_queue) 块
【发布时间】:2014-10-07 15:44:19
【问题描述】:

我正在努力更好地理解这个主题。假设我想做一些非常酷的动画,如下所示

- (void)coolAnimation 
{
    [UIView animateWithDuration: some duration
                     animations:^{ some animation }];
}

既然是动画块,它会自动添加到 main_queue 吗?或者为了获得最佳实践,我应该始终将 UI 更新添加到 main_queue,如下所示。

dispatch_async(dispatch_get_main_queue(), ^{
    [self coolAnimation];
});

【问题讨论】:

    标签: ios objective-c asynchronous uiview objective-c-blocks


    【解决方案1】:

    无论你在哪里调用[UIView animateWithDuration:animations:],你的块的内容都会在主线程上执行。最好让操作系统运行你的动画;动画线程不会阻塞主线程——只有动画块本身。

    在一个非常高级的手动波浪视图中,[UIView animateWithDuration:animations:] 评估您的块并确定其中每个可动画值的函数。操作系统有一个动画线程,它用作其帧计时器,然后在每个滴答声中,它会在主线程上向您的可动画属性发送一个更新及其进度值。 (您可以在您的presentationLayer 上检查这些值的当前状态。)

    【讨论】:

      【解决方案2】:

      您传递的动画块被称为立即。无需使用任何队列。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多