显示 UIProgressBarHUD 时禁用触摸

发布于 2024-08-06 13:29:12 字数 845 浏览 9 评论 0原文

我创建了一个应用程序,在其中创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

紧拥背影 2024-08-13 13:29:12

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

anyViewInYouApp.window.userInteractionsEnabled = NO;

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

You can disable user interaction with the nifty property named userInteractionsEnabled, that is defined for UIView. It just so happens that UIWindow is a subclass of UIView, we we can easily disable user interactions for out whole app.

anyViewInYouApp.window.userInteractionsEnabled = NO;

Or keep a reference to the window if you like.

送君千里 2024-08-13 13:29:12

在 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
}

In 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
}
獨角戲 2024-08-13 13:29:12

正如此处所指出的,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.

少女情怀诗 2024-08-13 13:29:12
UIWindow *win = [UIApplication sharedApplication].keyWindow;
[win setUserInteractionEnabled:NO];
UIWindow *win = [UIApplication sharedApplication].keyWindow;
[win setUserInteractionEnabled:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文