下面一段代碼是小編給大家介紹的swift3.0鍵盤彈起遮擋輸入框問題的解決方案代碼解析,具體代碼如下所示;
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})}}
好了,代碼到此結束,希望對大家有所幫助!
新聞熱點
疑難解答