swift基础--点击空白处收起键盘

1.全屏收起键盘

//注册监听

        self.view.addGestureRecognizer(UITapGestureRecognizer(target:self, action:#selector(当前ViewController.handleTap(sender:))))

//事件

    func handleTap(sender: UITapGestureRecognizer) {

        if sender.state == .ended {

            当前TextView/当前TextField.resignFirstResponder()

        }

        sender.cancelsTouchesInView = false

    }

持续更新..

你可能感兴趣的:(swift基础--点击空白处收起键盘)