Hide keyboard when scroll UITableView

前端 未结 8 2197
借酒劲吻你
借酒劲吻你 2020-12-02 05:47

In my app i want hide keyboard when i start scrolling UITableView. I search about this in internet, and most answer is subclassing UITableView (http://stackoverflow.com/ques

相关标签:
8条回答
  • 2020-12-02 06:09

    Here is the cleanest way to achieve this in iOS 7.0 and above:

    tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    

    Or to dismiss interactively when touching:

    tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
    

    Or in Swift:

    tableView.keyboardDismissMode = .onDrag
    

    To dismiss interactively:

    tableView.keyboardDismissMode = .interactive
    
    0 讨论(0)
  • 2020-12-02 06:13

    After iOS 7, you can simple use the tableview property

    Swift 3.0+

    myTableView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag
    

    ObjectiveC

    myTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    

    For earlier versions, implementing the scroll view delegate could work.

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
            view.endEditing(true)
    }
    
    0 讨论(0)
提交回复
热议问题