• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIKit如何在主线程被阻塞时绘制动画UIActivityIndi​​cator?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 02:16:16 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

我希望事件指示器出现在屏幕上但无法动画化,因为“测试” 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap