xcode 使用Swift 3的IQKeyboardManager与CustomTextField(SkyFloatingLabelTextField)

ej83mcc0  于 2023-05-19  发布在  Swift
关注(0)|答案(2)|浏览(108)

我正在使用SkyFloatingLabelTextField,这是一个自定义UITextField。在将IQKeyboardManager添加到我的Podfile(pod install)后,预计它将自动处理键盘问题。
有什么线索可以集成IQKeyboardManagercustomTextfield吗?

h9a6wy2h

h9a6wy2h1#

SWIFT 3.0+解决方案

在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
    }
}
3yhwsihp

3yhwsihp2#

你可以在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
    }

相关问题