biaobiaoqi
biaobiaoqi

Reputation: 1098

TapGestureRecognizer in the view made button from the view disable

I've got a uivew as a rootView. There is a button and a textfield in the view.

When textfield is in editting mode, the keyboard appears.

To dismiss keyboard, I add a uiTapGestureRecognizer to the whole view. So that When touch on the screen, keyboard will disappear.

But the button in the view will also get this gesture recognizer. When keyboard is showing, touch in the button can make it highlighted, but can not trigger the action of this button.

Is there any way to make the button action working when keyboard is showing in the view? Thanks a lot.

Upvotes: 0

Views: 148

Answers (1)

Rams
Rams

Reputation: 1751

UIGestureRecognizerDelegate in .h file

in .m

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

       if (touch.view == yourbutton )
    {
        return NO;
    }
    return YES;
}

Upvotes: 3

Related Questions