当活动指示器视图可见时,不允许用户交互 [英] Don't allow user interaction when activity indicator view is visible

查看:120
本文介绍了当活动指示器视图可见时,不允许用户交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个视图的视图。其中一个视图包含两个按钮和一些文本标签。另一个,alpha设置为0.25,有一个 UIActivityIndi​​catorView 告诉用户应用程序正在运行,他必须等到它完成。如果用户在 UIActivityIndi​​catorView 旋转时触摸按钮,当 UIActivityIndi​​catorView 停止时,应用程序会记住用户操作并且回应它。如何在 UIActivityIndi​​catorView 旋转时丢弃发生的用户交互?

I have a view which contains two views. One of those views contains two buttons and some text labels. The other one, with alpha set to 0.25, has an UIActivityIndicatorView to tell the user that the app is working and he must wait until it finishes. If the user touch a button while the UIActivityIndicatorView is spinning, when the UIActivityIndicatorView stops, the app remember the user action and responds to it. How can I discard the user interaction that occur while the UIActivityIndicatorView is spinning?

感谢阅读。

PD:喜欢在这个主题,我更喜欢不使用任何模态解决方案。

P.D.: Like is commented in this thread, I prefer do not to use any modal solution.

EDITED:

我目前正在使用此代码,但它无法正常工作。

I am currently using this code and it does not work right.

- (void)viewDidAppear:(BOOL)animated {

  // The view appears with an UIActivityIndicatorView spinning.
  [self showResults]; // The method that takes a long time to finish.
  [self.activityIndicator stopAnimating];
  // When the showResults method ends, the view shows the buttons to the user.
  [self.activityIndicatorView setHidden:YES];
  [self.menuButton setEnabled:YES];
  [self.menuButton setUserInteractionEnabled:YES];
  [self.playButton setEnabled:YES];
  [self.playButton setUserInteractionEnabled:YES];
  [self.view setUserInteractionEnabled:YES];
  [self.interactionView setUserInteractionEnabled:YES];
}


推荐答案

我发现这些方法非常有用:

I found these methods very useful:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

这篇关于当活动指示器视图可见时,不允许用户交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆