显示 UIProgressBarHUD 时禁用触摸
我创建了一个应用程序,在其中创建 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];
}
任何帮助将不胜感激! - 詹姆斯
I've created an app where I'm creating a UIProgressBarHUD to show that something is loading. My question is, how can I disable the view so nothing can be pressed untill the loading is finished?
I've tried setting:
[self.view setUserInterationEnabled:NO];
However this doesn't work :/
Here is the code I'm using for adding the 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];
}
Any help would be muchly appreciated!!
- James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用为
UIView
定义的名为userInteractionsEnabled
的漂亮属性来禁用用户交互。恰好UIWindow
是UIView
的子类,我们可以轻松地禁用整个应用程序的用户交互。或者如果您愿意,可以保留对窗口的引用。
You can disable user interaction with the nifty property named
userInteractionsEnabled
, that is defined forUIView
. It just so happens thatUIWindow
is a subclass ofUIView
, we we can easily disable user interactions for out whole app.Or keep a reference to the window if you like.
在 MBProgressHUD.m 中
In MBProgressHUD.m
正如此处所指出的,UIProgressHUD 是私有的。你不应该使用它。
有一个 库 可以为您提供所需的内容。
它允许您阻止用户在按您的请求更新时点击任何内容。
As pointed out here, UIProgressHUD is private. You should not use it.
There is a library that gives you what you are looking for though.
It allows you to keep the user from tapping anything while it is updating as you requested.