ダウン私は、私は2つのテキストフィールドとボタンがあり、その内、loginViewを持っています。 textFieldをタップしながらビューを上に移動し、リターンキーを押すとビューを下に移動する必要があります。キーボードが上に移動し、
私の問題は、それがすべての条件のために正常に動作しているが、1つのTextFieldビュー上のタップが上に移動している間、私たちは次のTextFieldビューのために行くと同時に、下に移動されていることです。その後、何のもののこの種を(自動的にTPKeyboardにより管理)を管理する機能の上に実現しないように...
使用TPKeyboardを質問をするための
import UIKit
class CheckFontIconView: UIViewController,UITextFieldDelegate {
var activeField: UITextField?
@IBOutlet weak var loginFieldsView: UIView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var mobileNo: UITextField!
@IBOutlet weak var textFieldPassword: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
mobileNo.delegate = self
textFieldPassword.delegate = self
registerForKeyboardNotifications()
}
@IBAction func btnLoginAction(_ sender: Any) {
}
deinit {
//NotificationCenter.default.removeObserver(self)
self.deregisterFromKeyboardNotifications()
}
func registerForKeyboardNotifications() {
//Adding notifies on keyboard appearing
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func deregisterFromKeyboardNotifications() {
//Removing notifies on keyboard appearing
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func keyboardWasShown(notification: NSNotification) {
//Need to calculate keyboard exact size due to Apple suggestions
var info = notification.userInfo!
let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
if self.activeField != nil {
self.loginFieldsView.frame.origin.y -= (keyboardSize?.height)!
}
}
func keyboardWillBeHidden(notification: NSNotification) {
//Once keyboard disappears, restore original positions
var info = notification.userInfo!
let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
self.loginFieldsView.frame.origin.y -= (keyboardSize?.height)!
self.loginFieldsView.endEditing(true)
}
func textFieldDidBeginEditing(_ textField: UITextField) {
self.activeField = textField
}
func textFieldDidEndEditing(_ textField: UITextField) {
self.activeField = nil
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
activeField?.resignFirstResponder()
return true
}
}
最も簡単な方法は、キーボードを表示するかどうかを示すフラグを設定することです。したがって、表示されていない場合にはそれを処理するか、次のtextFieldに移動します。 – nynohu
はい私は以前にフラグを設定したものを試しましたが、同じ問題が発生していました。 – kishor0011
ログインビューでUIScrollViewを使用する場合は、問題が修正される可能性があります。 –