我创建了一个应用程序,我正在创建一个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];
}
任何帮助都会非常感激!! - 詹姆斯
答案 0 :(得分:3)
您可以使用为userInteractionsEnabled
定义的名为UIView
的漂亮属性禁用用户互动。恰好UIWindow
是UIView
的子类,我们可以轻松禁用整个应用的用户互动。
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)
答案 3 :(得分:0)
UIWindow *win = [UIApplication sharedApplication].keyWindow;
[win setUserInteractionEnabled:NO];