Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: touch events are not sent to the next controller while a modal is dismissed

In my Storyboard I defined a modal segue. The corresponding modal view is dismissed via a button and a simple:

- (IBAction)dismiss:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        return;
    }];   
}

Everything works but the thing is, while this transition is occurring, if the user taps in the view of the "next" controller (i.e. the one that will replace the modal), touch events are not captured by this controller until the transition completes entirely.

My chain of controllers is:

UINavigationController -> visibleViewController -> modal Controller

(but note that the modal Controller is actually presented by the navigationController - that's how it is setup by default in the Storyboard).

How can you make sure that as soon as the transition starts, touch events are sent to the next controller?

like image 300
PJC Avatar asked Jan 10 '14 11:01

PJC


1 Answers

What you're describing is normal iOS behavior and not Model ViewController specific. Entering or exiting ViewControllers using push and pop will also wait for transition to end before receiving touch events on the destination ViewController.

A good solution to avoid this would be to present your ViewController in a container inside the first ViewController. Showing and dismissing the ViewController are under your responsibility and will require a bit more code (for example playing with the alpha channel of the container) but will give you more control on who and when a view receives touch events.

For example:

- (IBAction)hideContainer:(id)sender {   

    [UIView animateWithDuration:0.4 
                          delay:0.0         
                        options:UIViewAnimationOptionAllowUserInteraction
                     animations:^
                             {
                                 self.container.alpha = 0;
                             }
                     completion:^(BOOL finished){}];   
}
like image 196
Segev Avatar answered Nov 15 '22 18:11

Segev