Dismissing the keyboard in a UIScrollView

后端 未结 12 2307
醉话见心
醉话见心 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 21:02

    Look at keyboardDismissMode property of UIScrollView.

    // will hide keyboard when your text field is about to go beyond the keyboard.
    vwScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
    
    // will hide keyboard instantly once the scroll view started scrolling by user.
    vwScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissOnDrag;
    
    // If you need to hide keyboard on tap of scroll view,consider adding a tap gesture or sub class and override touchesbegan: method.
    

    Swift Version

    vwScrollView.keyboardDismissMode = .interactive
    vwScrollView.keyboardDismissMode = .onDrag
    

提交回复
热议问题