菜鸟教程小白 发表于 2022-12-13 02:16:16

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


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

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

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

<pre><code>- (void)viewDidLoad {
;
UIActivityIndicatorView *v = [ initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
;
v.center = self.view.center;
;
dispatch_async(dispatch_get_main_queue(), ^{
    while (1) {
      NSLog(@&#34;test&#34;);
    }
});
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><strong>核心动画编程指南</strong></p>

<p> <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimation_guide.pdf" rel="noreferrer noopener nofollow">https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimation_guide.pdf</a> </p>

<p>声明:</p>

<blockquote>
<p>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.</p>
</blockquote>

<p>并非所有的绘图都会发生在主线程上。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UIKit如何在主线程被阻塞时绘制动画UIActivityIndi​​cator?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/26088781/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/26088781/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UIKit如何在主线程被阻塞时绘制动画UIActivityIndi​​cator?