MBProgress的使用方法

1.MBProgressHUD 的弹窗的消息的界面,三种的方式:

第一种的方式: 

-(void)myTask{

    MBProgressHUD   *HUD = [[MBProgressHUD alloc] initWithView:self.view];

    [self.view addSubview:HUD];

     HUD.labelText = @"自动扫描中";

     [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

    sleep(10);

    [self show]; 

}

-(void)show {

    [self.HUD removeFromSuperview];

    TestViewController *test = [[TestViewController alloc]init];

    [self presentViewController:test animated:YES completion:nil];

}

 

第二种的方式:(使用了mb里面的回调的函数)

//使用了回调的方法

-(void)myTask1{

    int duration = 5;

    MBProgressHUD *HUD = [[MBProgressHUD alloc]initWithView:self.view];

    [self.view addSubview: HUD];

    HUD.labelText = @"正在登录,请稍等....";

    [HUD showAnimated:YES whileExecutingBlock:^{

        sleep(duration);

    } completionBlock:^{

        [HUD removeFromSuperview];

        [self show];

    }]; 

}

-(void)show {

    [self.HUD removeFromSuperview];

    TestViewController *test = [[TestViewController alloc]init];

    [self presentViewController:test animated:YES completion:nil];

}

第三种方式:(整个屏幕都充满)

-(void)myTask2{

     self.HUD = [[MBProgressHUD alloc]init];

    self.HUD = [MBProgressHUD showMessage:@"正在查询,请稍等片刻"];

    self.HUD.delegate = self;

    self.timer =   [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(show) userInfo:nil repeats:NO];   

}

-(void)show {

    [self.HUD removeFromSuperview];

    TestViewController *test = [[TestViewController alloc]init];

    [self presentViewController:test animated:YES completion:nil];

    }

#pragma  mark - MBProgressHUD (MB里面没有这个代理方法,新加了一个方法)

- (void)hudViewWasTapped{

     NSLog(@"调用hud的代理方法");

    [self.HUD removeFromSuperview];

    self.timer = nil;

    self.HUD = nil;

}

 

posted @ 2015-07-11 13:35  朱峰博客  阅读(4003)  评论(0编辑  收藏  举报