How to dismiss number pad keyboard by tapping anywhere

后端 未结 15 2205
梦如初夏
梦如初夏 2020-12-04 17:53

I\'d like to know the simplest code to dismiss the number pad keyboard when tapping anywhere outside the number pad. It\'s a simple application to input a number inside a te

15条回答
  •  广开言路
    2020-12-04 18:00

    Lots of answers here but still had to struggle to figure it out using XCode 5. Read this: https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html

    Add a Tap Gesture Recognizer to your UIScrollView. Set its delegate to be the viewcontroller.

    Add this method:

    - (IBAction)tappedSomewhere:(id)sender {
        [self.view endEditing:YES];
    }
    

    to your UIScrollView implementation code and associate it to the Tap Gesture Recognizer by control click and dragging to the implementation code.

    Worked for me.

提交回复
热议问题