Dismiss keyboard with swipe gesture (as in Message app)

后端 未结 8 788
萌比男神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:50

    I created a UIView category that provides the desired functionality:

    https://github.com/danielamitay/DAKeyboardControl

    Edit: It has indeed been used on the app store.

    0 讨论(0)
  • You can use UISwipeGestureRecognizer to do so. I don't know how to implement it using code, but if you are using the new xcode 4.2 beta then heres an easy method:

    1. Create an IBAction:

    - (IBAction)dismiss:(id)sender;

    1. Go to your view in your xib and set the class for you view to UIControl.

    2. Drag and connect the UISwipeGestureRecognizer from the Library to your view.

    3. Connect the IBAction (TouchDown) with the UISwipeGestureRecognizer.

    4. Write the code to dismiss the keyboard:

      - (IBAction)dismiss:(id)sender 
      
      {
      
        [yourTextField resignFirstResponder];
      
      }
      

    Done!

    0 讨论(0)
提交回复
热议问题