Dismissing the keyboard in a UIScrollView

后端 未结 12 2310
醉话见心
醉话见心 2020-11-30 20:18

Alright, I have a couple of UITextFields and UITextViews inside a UIScrollView, and I\'d like to set the keyboard to disappear wheneve

12条回答
  •  不知归路
    2020-11-30 20:49

    Although the essence is the same, I prefer less code.

    Setting the keyboard to disappear when the scrollView is scrolled in Attributes inspector:

    make keyboard disappear when scrollView is scrolled

    Then disappear keyboard when scrollView is tapped:

    1. Drag a Tap Gesture Recognizer onto your scrollView
    2. Ctrl-Drag
    3. Make an action
    4. Only one line in the action —— scrollView.endEditing(true). If you are using Objective-C, [self.scrollView endEditing: YES];

提交回复
热议问题