OGeek|极客世界-中国程序员成长平台

标题: ios - UIKit如何在主线程被阻塞时绘制动画UIActivityIndi​​cator? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:16
标题: ios - UIKit如何在主线程被阻塞时绘制动画UIActivityIndi​​cator?

考虑下面的代码。当它运行时,事件指示器出现并动画,同时“测试”被重复记录到控制台。为什么?

我希望事件指示器出现在屏幕上但无法动画化,因为“测试” block 在事件指示器的下一次重绘之前在主队列上执行,并且该 block 永远不会完成执行。

UIKit 是否从主线程中绘制事件指示器?

- (void)viewDidLoad {
  [super viewDidLoad];
  UIActivityIndicatorView *v = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  [self.view addSubview:v];
  v.center = self.view.center;
  [v startAnimating];
  dispatch_async(dispatch_get_main_queue(), ^{
    while (1) {
      NSLog(@"test");
    }
  });
}



Best Answer-推荐答案


核心动画编程指南

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimation_guide.pdf

声明:

Because it manipulates a static bitmap, layer-based drawing differssignificantly from more traditional view-based drawing techniques. With view-based drawing, changes to the view itself often result in a call to the view’s drawRect: method to redraw content using the new parameters. But drawing in this way is expensive because it is done using the CPU on the main thread. Core Animation avoids this expense by whenever possible by manipulating the cached bitmap in hardware to achieve the same or similar effects.

并非所有的绘图都会发生在主线程上。

关于ios - UIKit如何在主线程被阻塞时绘制动画UIActivityIndi​​cator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26088781/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4