gpt4 book ai didi

iphone - 核心动画警告 : "uncommitted CATransaction"

转载 作者:行者123 更新时间:2023-11-28 22:42:32 26 4
gpt4 key购买 nike

我仅在设备上收到以下警告:

CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0 QuartzCore 0x3763c65d <redacted> + 220
1 QuartzCore 0x3763c541 <redacted> + 224
2 QuartzCore 0x3763fe2f <redacted> + 30
3 QuartzCore 0x3763b9bf <redacted> + 318
4 QuartzCore 0x3763b87b <redacted> + 50
5 QuartzCore 0x3763b80b <redacted> + 538
6 MyApp 0x000df597 -[CommonClass orangeGradient:] + 382
7 MyApp 0x000f70e1 -[HomeViewController updateStatusBar] + 1700
8 MyApp 0x000f61bd -[HomeViewController statusRecieved] + 224
9 MyApp 0x000cd323 -[CommonClass statusReceivedFromServer] + 142
10 MyApp 0x000d833d -[CommonClass accountStatus] + 7416
11 Foundation 0x35a3767d <redacted> + 972
12 libsystem_c.dylib 0x35c9a311 <redacted> + 308
13 libsystem_c.dylib 0x35c9a1d8 thread_start + 8

我在栈顶的方法如下:

- (void)orangeGradient: (UILabel *)fillLabel {
@synchronized([CommonClass class]) {
CAGradientLayer * gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = fillLabel.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(0xfbb250) CGColor],(id)[UIColorFromRGB(0xf47c2a) CGColor], nil];
[fillLabel.layer addSublayer:gradientLayer];
}
}

知道为什么会出现这种情况,我该如何解决?

最佳答案

看起来 orangeGradient: 是从后台线程调用的。 Core Animation 将所有更改分组到 CATransactions 中。通常这是从运行循环自动完成的。在后台线程上(通常)没有运行循环,因此您必须自己创建事务:

- (void)orangeGradient: (UILabel *)fillLabel {
@synchronized([CommonClass class]) {
[CATransaction begin];
CAGradientLayer * gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = fillLabel.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(0xfbb250) CGColor],(id)[UIColorFromRGB(0xf47c2a) CGColor], nil];
[fillLabel.layer addSublayer:gradientLayer];
[CATransaction commit];
}
}

还有一个问题:UIKit 不是线程安全的。您不能在后台线程的 UILabel 上调用 bounds

关于iphone - 核心动画警告 : "uncommitted CATransaction",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14120604/

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