Dismiss keyboard with swipe gesture (as in Message app)

后端 未结 8 769
萌比男神i
萌比男神i 2021-01-30 17:25

When the keyboard is showing on the iPhone\'s Messages app, if the user begins a swipe down from the messages tableview and continues into the keyboard area, the keyboard will b

8条回答
  •  有刺的猬
    2021-01-30 17:39

    Luckily, Apple added the handy property keyboardDismissMode on UIScrollView to make your life a little easier.

    Now your app can behave like Messages.app just by changing a single property on your Storyboard, or alternatively by adding one line of code!

    This property uses the new UIScrollViewKeyboardDismissMode enum. The possible values of this enum are as follows:

    UIScrollViewKeyboardDismissModeNone        // the keyboard is not dismissed    automatically when scrolling
    UIScrollViewKeyboardDismissModeOnDrag      // dismisses the keyboard when a drag begins
    UIScrollViewKeyboardDismissModeInteractive // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss
    

    Here’s the Storyboard property to change to dismiss the keyboard on scroll:

    Hope that helps solving your problem

提交回复
热议问题