- classAddDayReportViewController:UITableViewController{
- @IBOutletweakvarworkcontent:UITextView!
- overridefuncviewDidLoad(){
- super.viewDidLoad()
- //注册点击事件
- view.addGestureRecognizer(UITapGestureRecognizer(target:self,action:"handleTap:"))
- }
- funchandleTap(sender:UITapGestureRecognizer){
- ifsender.state==.Ended{
- print("收回键盘")
- workcontent.resignFirstResponder()
- }
- sender.cancelsTouchesInView=false
- }
UIGestureRecognizer类用于手势识别,它的子类有主要有六个分别是:
UITapGestureRecognizer(轻击一下)
UIPinchGestureRecognizer(两指控制的缩放)
UIRotationGestureRecognizer(旋转)
UISwipeGestureRecognizer(滑动,快速移动)
UIPanGestureRecognizer(拖移,慢慢移动)
UILongPressGestureRecognizer(长按) 原文链接:https://www.f2er.com/swift/323561.html