用戶可以通過單擊按鈕來下載一組地圖,完成該任務後,我想隱藏進度指示器。我已經嘗試了以下代碼的幾種變體,但尚未實現我正在尋找的功能。任何指導將不勝感激。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