用户可以通过单击按钮来下载一组地图,完成该任务后,我想隐藏进度指示器。我已经尝试了以下代码的几种变体,但尚未实现我正在寻找的功能。任何指导将不胜感激。MBProgressHUD GCD之后的隐藏指示器
- (IBAction)SavePhotoOnClick:(id)sender{
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSURL *url = [NSURL URLWithString:urlstr1];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});
// Set determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
HUD.dimBackground = YES;
HUD.color = [UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];
HUD.delegate = self;
HUD.labelText = @"Downloading Maps";
// myProgressTask uses the HUD instance to update progress
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
}
- (void)myProgressTask {
// This just increases the progress indicator in a loop
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep(40000);
}
}
删除progresstask方法和showWhileExecuting代码将删除进度指示器。看起来,使用者会覆盖所有内容,并且不允许在下载完成后隐藏进度指示器,而是在4秒后将其删除。
这个工作,我以前做过。出于某种原因,但是当我使用该调用时,它不允许我添加文本,颜色等。我对进度指示器的确定状态没有太大的限制,假设我可以添加一些文字说“正在下载.. “任何protips? – 3722839
我相信MBProgressHUD实例具有可以设置为自定义外观的“文本”参数。 –
是的,但是,这些参数似乎不适用于我们目前的解决方案。我需要进一步调查它,我想。 – 3722839