Display keyboard without animation

后端 未结 7 1502
感情败类
感情败类 2020-11-29 03:12

Looked intoUIKeyboardAnimationDurationUserInfoKey but I just can\'t find anywhere how to set it to a custom value.

7条回答
  •  渐次进展
    2020-11-29 03:35

    The answer of @Vadoff works perfect. Here for Swift 3:

        override func viewDidLoad() {
            super.viewDidLoad()
    
            //...
    
            // Add observer to notificationCenter so that the method didShowKeyboard(_:) is called when the keyboard did show.
            NotificationCenter.default.addObserver(self, selector: #selector(type(of: self).didShowKeyboard(_:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
    
            // Make textField the first responder.
            textField.becomeFirstResponder() // <- Change textField to the name of your textField.
        }
    
        func textFieldDidBeginEditing(_ textField: UITextField) {
            // Disable animations.
            UIView.setAnimationsEnabled(false)
        }
        func didShowKeyboard(_ notification: Notification) {
            // Enable animations.
            UIView.setAnimationsEnabled(true)
        }
    

提交回复
热议问题