通知,键盘隐藏

时间:2017-03-14 05:55:25

标签: ios swift notifications

<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" id="showvideo">Open Modal</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<video width="400" controls>
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>


$('#showvideo').click(function(){
$("video").html('<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4" type="video/mp4">');
$("video")[0].load();
$('#myModal').modal('show');
$('video')[0].play();
});
$('#myModal').on('hidden.bs.modal', function () {
$("video").html('');
$("video")[0].load();
})

我添加两个通知(键盘向上,向下)。我想在触摸返回按钮时隐藏键盘。但是keyboardWillHide()方法没有调用。我错了或错过了什么?

2 个答案:

答案 0 :(得分:0)

首先是

1.使您的ViewController确认textField委托

class YourViewController: UIViewController, UITextFieldDelegate {

}

2.将self设置为textField委托

override func viewDidLoad() {
    super.viewDidLoad()
    self.yourTextField.delegate = self
}

3。实施

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    self.yourTextField.resignFirstResponder()
    return true
}

答案 1 :(得分:0)

如果您使用的是UITextField,请设置委托并覆盖此方法:

optional func textFieldShouldReturn(_ textField: UITextField) -> Bool

命中返回键时会调用此方法。然后你打电话

textField.resignFirstResponder()

然后键盘将被解雇。