Don't allow user interaction when activity indicator view is visible

后端 未结 10 2072
你的背包
你的背包 2020-12-24 02:30

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 UIActivityIndicator

相关标签:
10条回答
  • 2020-12-24 03:14

    I found these methods very useful:

    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    
    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
    
    0 讨论(0)
  • 2020-12-24 03:21
    @IBAction func yourButtonPressed(sender: UIButton) {
    if self.activityIndicator.isAnimating() {
    //remember the action user asked of you using the sender
    } else {
    //do your stuff
    return
    }
    yourButtonPressed(yourButton)
    }
    

    or you code use self.activityIndicator.animationDidStop to determine when to run your stuff

    0 讨论(0)
  • 2020-12-24 03:23

    A quick solution: add a transparent or pseudo transparent view that cover the whole screen. Add your activity indicator on top of this view. When the wait period finishes, remove both views. Get some inspiration.

    A better solution, because you can't hide the whole screen in all situations, is to manage the state of the app (ignore actions when the app is 'busy') and disable/enable the appropriate buttons and other controls depending on each app state.

    0 讨论(0)
  • 2020-12-24 03:27

    To disable touch event in a view,

    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    

    To enable touch event in a view

    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
    
    0 讨论(0)
提交回复
热议问题