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(长按)