• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - MBProgressHUD 宽限时间和最小时间无法正常工作。如何实现。?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:15:06 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在使用 MBProgressHUD用于在执行本地长方法时显示加载,以提供用户良好的体验。一切正常,但现在我必须像这样实现,如果该方法在一秒钟内执行,则不应出现加载。我浏览了 MBProgressHUD 示例,对于这个功能,我发现 setGraceTimesetMinShowTime 显示时间,但它们都不能正常工作。因为当我设置宽限时间时,即使方法执行时间超过 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-推荐答案


您需要在方法执行中从其父 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap