zoukankan      html  css  js  c++  java
  • MBProgressHUD 优雅地去提示

    项目主页: MBProgressHUD

    实例下载: 点击下载

    快速上手:

    当执行需要较长时间的任务时,使用MBProgressHUD最重要的一点是: 保证主线程是空闲的,这样可以使UI实时更新.因此: 建议在 主线程中使用 MBProgressHUD, 把其他你想要执行的任务放到其他的线程里:

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        // 执行某些任务...
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        });
    });

    如果你想配置 HUD,你可以使用由 showHUDAddedTo:animated: 方法返回的 MBProgressHUD 的实例.

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeAnnularDeterminate;
    hud.labelText = @"Loading";
    
    // doSomethngInBackgroudWithProgressCallback: 代指某个和进度有关的 自定义方法.
    [self doSomethingInBackgroundWithProgressCallback:^(float progress) {
        hud.progress = progress;
    } completionCallback:^{
        [hud hide:YES];
    }];

    UI 更新,应该通常总是在主线程完成.但是某些 MBProgressHUD 设置器,考虑到了”线程安全”,并且可以在后台线程里被调用.这些设置器,具体指的是: setMode:,setCustomView:setLabelText:setLabelFont:setDetailsLabelText:,setDetailsLabelFont: 和 setProgress:.

    如果你需要在主线程执行需要长时间运行的任务,你应该在短暂的延迟后再执行这个任务,这样在你的任务阻塞主线程之前, UIKit 就有足够的时间来更新UI(如,绘制HUD).

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // 执行某个 耗时较长的操作.
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    });
  • 相关阅读:
    初学三种神经网络(前馈,竞争,递归联想存储网络)
    链表操作,空间复杂度要求为O(1)
    单链表的回文判断(O(n)时间复杂度和O(1)的空间复杂度)
    Floyd算法小结
    排序算法Java实现(基数排序)
    排序算法Java实现(归并排序)
    排序算法Java实现(堆排序)
    排序算法Java实现(选择排序)
    排序算法Java实现(快速排序)
    排序算法Java实现(冒泡排序)
  • 原文地址:https://www.cnblogs.com/ios122/p/MBProgressHUD.html
Copyright © 2011-2022 走看看