【发布时间】:2014-07-10 00:16:29
【问题描述】:
用户可以单击按钮下载一组地图,完成该任务后,我想隐藏进度指示器。我已经尝试了以下代码的几种变体,但没有实现我正在寻找的内容。任何指导将不胜感激。
- (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 代码会删除进度指示器。似乎 usleep 覆盖了所有内容,并且不允许在下载完成后隐藏进度指示器,而是在 4 秒后将其删除。
【问题讨论】:
标签: ios objective-c grand-central-dispatch mbprogresshud