1. class AddDayReportViewController: UITableViewController {
2.
3.
4. @IBOutlet weak var workcontent: UITextView!
5.
6. override func viewDidLoad() {
7. super.viewDidLoad()
8.
9. //注册点击事件
10. view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "handleTap:"))
11. }
12.
13. func handleTap(sender: UITapGestureRecognizer) {
14. if sender.state == .Ended {
15. print("收回键盘")
16. workcontent.resignFirstResponder()
17. }
18. sender.cancelsTouchesInView = false
19. }
20.
亲测可用!!
UIGestureRecognizer类用于手势识别,它的子类有主要有六个分别是:
UITapGestureRecognizer(轻击一下)
UIPinchGestureRecognizer(两指控制的缩放)
UIRotationGestureRecognizer(旋转)
UISwipeGestureRecognizer(滑动,快速移动)
UIPanGestureRecognizer(拖移,慢慢移动)
UILongPressGestureRecognizer(长按)
swift 点击空白键盘下去
转载上一篇:Swift定义一个全局变量字符串
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章