Ios7 如何缩短显示加载器的初始时间?
我正在用按钮操作实现加载器,但当我点击按钮时,开始加载需要3到5秒。我使用两个控制器来实现loader-UIImage+animatedGIF.h来使用gif-image和MBProgressHUD.h来实现进度时间。我不知道如何减少启动loader所需的初始时间。 我使用这段代码来实现loader-Ios7 如何缩短显示加载器的初始时间?,ios7,xcode5,nstimer,gif,loader,Ios7,Xcode5,Nstimer,Gif,Loader,我正在用按钮操作实现加载器,但当我点击按钮时,开始加载需要3到5秒。我使用两个控制器来实现loader-UIImage+animatedGIF.h来使用gif-image和MBProgressHUD.h来实现进度时间。我不知道如何减少启动loader所需的初始时间。 我使用这段代码来实现loader- NSURL *url = [[NSBundle mainBundle] URLForResource:@"loadingg" withExtension:@"gif"]; self.lo
NSURL *url = [[NSBundle mainBundle] URLForResource:@"loadingg" withExtension:@"gif"];
self.loader.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
// HUD.progress = progress;
usleep(50000);
}
[NSTimer scheduledTimerWithTimeInterval:progress target:self selector:@selector(abcd) userInfo:nil repeats:NO];
原因是,在您从代理返回之前,它不会显示您的图像,并且由于您使用while循环阻止代理5秒钟,您会体验到您描述的行为,我必须假设usleep50000不在主线程上 如果是,则会延迟5秒。休眠主线程只是为了:等等。正确的方法是异步加载 阅读@bbum建议,了解何时适合调用usleep: