swift 点击空白键盘下去

前端之家收集整理的这篇文章主要介绍了swift 点击空白键盘下去前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. classAddDayReportViewController:UITableViewController{
  2. @IBOutletweakvarworkcontent:UITextView!
  3. overridefuncviewDidLoad(){
  4. super.viewDidLoad()
  5. //注册点击事件
  6. view.addGestureRecognizer(UITapGestureRecognizer(target:self,action:"handleTap:"))
  7. }
  8. funchandleTap(sender:UITapGestureRecognizer){
  9. ifsender.state==.Ended{
  10. print("收回键盘")
  11. workcontent.resignFirstResponder()
  12. }
  13. sender.cancelsTouchesInView=false
  14. }
亲测可用!!

UIGestureRecognizer类用于手势识别,它的子类有主要有六个分别是:
UITapGestureRecognizer(轻击一下)
UIPinchGestureRecognizer(两指控制的缩放)
UIRotationGestureRecognizer(旋转)
UISwipeGestureRecognizer(滑动,快速移动)
UIPanGestureRecognizer(拖移,慢慢移动)
UILongPressGestureRecognizer(长按) 原文链接:https://www.f2er.com/swift/323561.html

猜你在找的Swift相关文章