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

后端 未结 10 2026
你的背包
你的背包 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:00

    Use SVProgressHUD WrapperClass It have so many options to show ActivityIndicator
    For Source Code Click Here !

    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];


    use above statement to disable background touches

    [SVProgressHUD dismiss]

    To enable background touches.

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

    Though answer is replied in earlier response, just like to add for information purpose "[self.activityIndicatorView setHidden:YES];" no need to call this method explicitly, because startAnimating/stopAnimating already take care of this. I'm assuming you are using default value of "hidesWhenStopped" property.

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

    just add

    [self.view setUserInteractionEnabled:NO];  
    

    before the

    [self.activityIndicator startAnimating];  
    

    and reenable it after

    [self.activityIndicator stopAnimating];
    [self.view setUserInteractionEnabled:YES]; 
    
    0 讨论(0)
  • 2020-12-24 03:05

    In Swift 3.0 To Disable interaction :-

    UIApplication.shared.beginIgnoringInteractionEvents()
    

    To restore interaction :-

    UIApplication.shared.endIgnoringInteractionEvents()
    
    0 讨论(0)
  • 2020-12-24 03:07
    [_button setUserInteractionEnabled:NO];
    

    That should disable it, just set YES for when you want to user to tap it.

    BOOL i_am_ready_to_submit = NO;
    
    -(void)action_finished{
    
    [self.activityIndicator stopAnimating];
    
    i_am_ready_to_submit = YES;
    
    }
    
    -(IBAction)submit_button{
    
    if(i_am_ready_to_submit){
    
    [self submit];
    
    }
    
    }
    
    0 讨论(0)
  • 2020-12-24 03:13

    You could disable/enable the UIButtons based on the UIActivityIndicatorView being shown or not. Or, if you just want to "discard the user interaction" while the spinner is shown, in the button handler method:

    - (void)buttonTapped:(id)sender {
        if ([spinner superview] != nil && [spinner isAnimating]) {
            return;
        }
        // ... the rest of your code
    }
    

    This example assumes that when you hide the UIActivityIndicatorView you call one of:

    [spinner removeFromSuperview];
    

    or

    [spinner stopAnimating];
    
    0 讨论(0)
提交回复
热议问题