iOS: 下载等待画面open source lib - MBProgressHUD

MBProgressHUD的原理

http://iphonedevelopment.blogspot.com/2010/02/implementing-wait.html


Download

https://github.com/jdg/MBProgressHUD


Installation

下载解压之后,把下列两个file copy to your project即可。

MBProgressHUD.h

MBProgressHUD.m


How to use?

完整例子参看下载zip file里的Demo目录下的example project。

最简单的使用代码:

#import"MBProgressHUD.h"

...

// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)

// 参数initWithView的值应该是the highest view possible,

//在MBProgressHUD zip file提供的example里该参数值为self.navigationController.view,

//但如果你创建的是single view project的话,就会出错,因为self.navigationController is nil

MBProgressHUD *hud = [[MBProgressHUDalloc]initWithView:self.view];

[self.viewaddSubview:hud];

// Regiser for HUD callbacks so we can remove it from the window at the right time

// self必须在.h file里声明实现 "<MBProgressHUDDelegate>" 接口,同时在.m file里添加"hudWasHidden" method

//该方法是一个回调方法,当你执行"[hud hide:YES];"时,就会回调它

hud.delegate =self;

    

//show pregress hud

[hud show:YES];


上面的代码是创建和显示Progress Hud。下面的代码 are for close progress hud。

首先你的viewcontroller.m里要实现"<MBProgressHUDDelegate>" 接口的"hudWasHidden" method,该方法是一个回调方法,当你执行"[hud hide:YES];"时,就会回调它

- (void)hudWasHidden:(MBProgressHUD *)hud {

// Remove HUD from screen when the HUD was hidded

[hudremoveFromSuperview];

hud =nil;

}


然后在你要关闭progress hud的地方执行下列代码:

[hudshow:YES];




其实你也可以不使用MBProgressHUDDelegate接口和hudWasHidden方法,而是用手动代码来close progress hud。其做法是:
* 删除<MBProgressHUDDelegate> in .m file
* 删除  hud.delegate = self;
* 删除 hudWasHidden 方法
* 最后在你要关闭progress hud的地方执行下列代码

[hud show:YES];

[hud removeFromSuperview];

hud = nil;









你可能感兴趣的:(ios,File,input,hierarchy,2010)