我正在使用 MBProgressHUD用于在执行本地长方法时显示加载,以提供用户良好的体验。一切正常,但现在我必须像这样实现,如果该方法在一秒钟内执行,则不应出现加载。我浏览了 MBProgressHUD 示例,对于这个功能,我发现 setGraceTime 和 setMinShowTime 显示时间,但它们都不能正常工作。因为当我设置宽限时间时,即使方法执行时间超过 1 秒,加载图标也不会出现。这是我的代码
if (self.HUD == nil)
{
self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.HUD];
}
self.HUD.labelText = @"lease wait.....";
// [self.HUD setMinShowTime:2.0f];
[self.HUD setGraceTime:1.0f];
[self.HUD setTaskInProgress:YES];
[self.HUD show:YES];
// [self.HUD hide:YES afterDelay:3];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]];
if (mycondition == nil)
{
[self myTask:[NSURL fileURLWithPath:strPath]];
//[self performSelectorselector(mytask withObject:[NSURL fileURLWithPath:strPath]];
}
else
{
//else
}
self.tempView.hidden = YES;
// self.HUD.taskInProgress = NO;
[self.HUD hide:YES];
self.HUD = nil;
我已经为 this problem's solution 添加了 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distinctPast]];
请指导我这段代码有什么问题..?!
Best Answer-推荐答案 strong>
您需要在方法执行中从其父 View 中移除 MBProgressHUD 对象。
像这样:
// if the method runs inside one second, the indicator will not be
shown
- (void)viewDidLoad
{
[super viewDidLoad];
if (HUD == nil)
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
}
HUD.labelText = @"lease wait.....";
[HUD setGraceTime:1.0f];
[HUD setTaskInProgress:YES];
[HUD show:YES];
[self performSelectorselector(runThisMethod) withObject:nil afterDelay:0.9f];
}
- (void)runThisMethod
{
[HUD removeFromSuperview];
}
// if the method runs after one second, the indicator will be
shown for some time until the method runs
- (void)viewDidLoad
{
[super viewDidLoad];
if (HUD == nil)
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
}
HUD.labelText = @"lease wait.....";
[HUD setGraceTime:1.0f];
[HUD setTaskInProgress:YES];
[HUD show:YES];
[self performSelectorselector(runThisMethod) withObject:nil afterDelay:1.9f];
}
- (void)runThisMethod
{
[HUD removeFromSuperview];
}
关于ios - MBProgressHUD 宽限时间和最小时间无法正常工作。如何实现。?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/18008708/
|