我正在使用
SkyFloatingLabelTextField
,这是自定义的 UITextField
。将 IQKeyboardManager
添加到我的 Podfile (pod install
) 后,预计它会自动处理键盘问题。
有什么线索可以将
IQKeyboardManager
与 customTextfield
整合起来吗?
解决方案
在 AppDelegate 中:
// Enable IQKeyboardManager for customization
IQKeyboardManager.sharedManager().enable = true
在 UIViewController 中
class A : UIViewController
viewDidLoad() {
customizeKeyboard()
}
func customizeKeyboard(){
IQKeyboardManager.sharedManager().shouldResignOnTouchOutside = true
IQKeyboardManager.sharedManager().shouldShowTextFieldPlaceholder = false
IQKeyboardManager.sharedManager().toolbarDoneBarButtonItemText = ""
IQKeyboardManager.sharedManager().shouldHidePreviousNext = true
IQKeyboardManager.sharedManager().keyboardDistanceFromTextField = 150
emailTextField.delegate = self
passwordTextField.delegate = self
// to remove the autocorrect on top of keyboard
emailTextField.autocorrectionType = .no
emailTextField.keyboardType = .emailAddress
// to remove the IQManager view on top of Keyboard
let emptyUIView = UIView()
emailTextField.inputAccessoryView = emptyUIView
passwordTextField.inputAccessoryView = emptyUIView
forgotEmailTextField.inputAccessoryView = emptyUIView
}
}
您可以在 SceneDelegate.swift 中设置键盘设置,只需添加此代码...
// MARK: - IQKeyboard settings
func setupIQKeyboard()
{
//Enabling keyboard manager
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.keyboardDistanceFromTextField = 15
//Enabling autoToolbar behaviour. If It is set to NO. You have to manually create IQToolbar for keyboard.
IQKeyboardManager.shared.enableAutoToolbar = true
IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "Done"
//Setting toolbar behavious to IQAutoToolbarBySubviews. Set it to IQAutoToolbarByTag to manage previous/next according to UITextField's tag property in increasing order.
IQKeyboardManager.shared.toolbarManageBehaviour = .bySubviews
//Resign textField if touched outside of UITextField/UITextView.
IQKeyboardManager.shared.shouldResignOnTouchOutside = true;
//Show TextField placeholder texts on autoToolbar
IQKeyboardManager.shared.shouldShowToolbarPlaceholder = true
IQKeyboardManager.shared.previousNextDisplayMode = .alwaysShow
}