gpt4 book ai didi

ios - 处理 JSON 时动画卡住

转载 作者:行者123 更新时间:2023-11-29 12:31:30 25 4
gpt4 key购买 nike

我有一个自定义动画,我正在使用此方法调用:

- (void)spinWithOptions:(UIViewAnimationOptions)options directionForward:(BOOL)directionForward {

[UIView animateWithDuration:0.3
delay:0.0
options:options
animations:^{

CATransform3D transform;

if (!directionForward) {

transform = CATransform3DIdentity;

} else {

transform = CATransform3DIdentity;
transform.m34 = -1.0 / 500.0;
transform = CATransform3DRotate(transform, M_PI - 0.0001f /*full rotation*/, 0, 1, 0.0f);

}

self.logoImageView.layer.transform = transform;

} completion:^(BOOL finished) {

if (!_animating && options != UIViewAnimationOptionCurveEaseOut) {

[self spinWithOptions:UIViewAnimationOptionCurveEaseOut directionForward:NO];

} else if (options == UIViewAnimationOptionCurveLinear) {

[self spinWithOptions:UIViewAnimationOptionCurveLinear directionForward:!directionForward];

} else {

// animation finished

}

}];

但我有一个问题,当动画运行并且我从服务器使用 AFNetworkingCoreData 进行一些处理时动画卡住,我认为主线程被阻塞但我还有一个 MBProgresHUD 并且不会卡住。知道如何让这个动画不卡住吗?

最佳答案

您在同一个线程上制作动画和所有网络。但是一次只能在一个线程上运行一件事,因此您的加载会阻止动画。

您需要卸载任务,以便线程可以只运行一件事。任何 ui 修改都需要在主线程上进行,因此我们卸载了网络。

- startMyLongMethod {
[self startAnimation]; //your spin thingy

//get a background thread from GCD and do the work there
dispatch_async(dispatch_get_global_queue(0,0), ^{
//do longRunning op (afnetwork and json parsing!)
id result = [self doWork];

//go back to the main thread and stop the animation
dispatch_async(dispatch_get_main_queue(), ^{
[self updateUI:result];
[self stopAnimation];//your spin thingy
});
});

注意:示例代码和内联编写!不过现在方法应该很清楚了

关于ios - 处理 JSON 时动画卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27545714/

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