下面一段代码是小编给大家介绍的swift3.0键盘弹起遮挡输入框问题的解决方案代码解析,具体代码如下所示;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
extension LoginViewController:UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() //键盘收回,view放下 UIView.animate(withDuration: 0.4 , animations: { self.view.frame.origin.y = 0 }) return true } func textFieldDidBeginEditing(_ textView:UITextField) { //view弹起跟随键盘,高可根据自己定义 UIView.animate(withDuration: 0.4 , animations: { self.view.frame.origin.y = - 150 }) } } |
好了,代码到此结束,希望对大家有所帮助!
原文链接:http://blog.csdn.net/wuyanyanstrong/article/details/53405586