Pheepster
Pheepster

Reputation: 6357

Prevent a swipe gesture while another UIViewController is present

I have an app that has a mode that users enter into when editing a geographic feature. While in this editing mode, I present a view controller with an embedded tableview that is inset from the view controller's frame. The background of this view controller has an alpha of 0.5 so the underlying view is still partially visible outside of the inner table view, though grayed out by the semi-opaque view controller on top. There is a button on the underlying view controller that is used to slide the view to the right when not in editing mode.

While the editing view controller is active, this button to activate the slider is disabled, which is desired behavior. However, users can also swipe the view to the right which achieves the same things a the button. i would like to disable this swipe feature while the editing view controller is present.

So I guess my question is: how can I disable a swipe gesture when a certain view controller is present?

Upvotes: 0

Views: 223

Answers (1)

Lyndsey Scott
Lyndsey Scott

Reputation: 37290

You can use the gestureRecognizerShouldBegin: delegate method. If the detected gesture is that particular swipe gesture (i.e. theGesture) and that certain view controller is present (i.e. theView), tell the gesture not to begin, ex:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    if (gestureRecognizer == theGesture && theView.window != nil) {
        return NO;
    } else {
        return YES;
    }
}

Upvotes: 1

Related Questions