显示UIProgressBarHUD时禁用触摸

时间:2009-10-01 15:56:11

标签: iphone objective-c uiprogressbar

我创建了一个应用程序,我正在创建一个UIProgressBarHUD以显示正在加载的内容。我的问题是,如何禁用视图,以便在加载完成后无法按下任何内容?

我尝试过设置:

[self.view setUserInterationEnabled:NO];

但是这不起作用:/

以下是我用于添加UIProgressHUD的代码:

- (IBAction) showHUD:(id)sender
{
       //[self.view setUserInteractionEnabled:NO];

       UIProgressHUD *HUD = [[UIProgressHUD alloc]
initWithWindow:[[UIApplication sharedApplication] keyWindow]];
       [HUD setText:@"Loading…"];
       [HUD show:YES];

       [HUD performSelector:@selector(done) withObject:nil afterDelay:1.5];
       [HUD performSelector:@selector(setText:) withObject:@"Done!"
afterDelay:1.5];
       [HUD performSelector:@selector(hide) withObject:nil afterDelay:4.0];

       //[self.view setUserInteractionEnabled:YES];

       [HUD release];
}

任何帮助都会非常感激!! - 詹姆斯

4 个答案:

答案 0 :(得分:3)

您可以使用为userInteractionsEnabled定义的名为UIView的漂亮属性禁用用户互动。恰好UIWindowUIView的子类,我们可以轻松禁用整个应用的用户互动。

anyViewInYouApp.window.userInteractionsEnabled = NO;

如果您愿意,可以保留对窗口的引用。

答案 1 :(得分:3)

在MBProgressHUD.m

#define APPDELEGATE                         
(TMAppDelegate *)[[UIApplication sharedApplication]delegate]

- (void)show:(BOOL)animated 
{
    [[APPDELEGATE window] setUserInteractionEnabled:NO]; //use this line
}

- (void)hide:(BOOL)animated 
{  
    [[APPDELEGATE window] setUserInteractionEnabled:YES]; //use this line
}

答案 2 :(得分:1)

正如here所指出的,UIProgressHUD是私有的。你不应该使用它。

虽然有library可以为您提供所需的内容。

它允许您在用户请求时更新任何内容。

答案 3 :(得分:0)

UIWindow *win = [UIApplication sharedApplication].keyWindow;
[win setUserInteractionEnabled:NO];