gpt4 book ai didi

ios - 动画还在,当主线程做其他事情时

转载 作者:行者123 更新时间:2023-11-28 21:55:49 24 4
gpt4 key购买 nike

这是我的代码。这很简单。我的问题是为什么当主线程做其他事情时动画仍然存在,文档说主线程可以更新用户界面。主线程可以同时做两件事???

可能是 GPU 制作动画?

- (void)viewDidLoad {
[super viewDidLoad];
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 80, 50)];
testLabel.font = [UIFont systemFontOfSize:15.0f];
testLabel.backgroundColor = [UIColor redColor];
testLabel.text = @"Hello world";
testLabel.adjustsFontSizeToFitWidth = YES;
[self.view addSubview:testLabel];

[UIView animateWithDuration:10
animations:^{
testLabel.frame = CGRectMake(100, 200, 80, 50);
} completion:^(BOOL finished) {
//
}];
[self performSelector:@selector(hello:) withObject:@"hello" afterDelay:2];
}


- (void)hello:(NSString *)hello{
for (int i = 0; i < 100000; i++) {
NSInteger j = i *5;
NSLog(@"%d",j);
}
NSLog(@"%@",hello);
}

最佳答案

动画在图形硬件中运行,甚至不占用 CPU。

核心动画在UIKit下,所以当你使用UIViewanimateWithDuration:animations:completion:时,你实际上是在使用核心动画。

我引用了 CoreAnimation_guide 中的一段:

Core Animation is a graphics rendering and animation infrastructure available on both iOS and OS X that you use to animate the views and other visual elements of your app. With Core Animation, most of the work required to draw each frame of an animation is done for you. All you have to do is configure a few animation parameters (such as the start and end points) and tell Core Animation to start. Core Animation does the rest, handing most of the actual drawing work off to the onboard graphics hardware to accelerate the rendering. This automatic graphics acceleration results in high frame rates and smooth animations without burdening the CPU and slowing down your app.

我认为回答你的问题已经足够清楚了。

关于ios - 动画还在,当主线程做其他事情时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26623240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com