Hide keyboard when scroll UITableView

前端 未结 8 2226
借酒劲吻你
借酒劲吻你 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: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)
    }
    

提交回复
热议问题