gpt4 book ai didi

ios - 如果用户双击文本字段,键盘会变黑

转载 作者:行者123 更新时间:2023-11-29 01:28:57 25 4
gpt4 key购买 nike

我有一个注册页面,其中有 3 个文本字段。触摸文本字段时, View 会向上滑动,以便在显示键盘时可以看到这些字段。但是,如果用户快速点击文本框两次,而不是点击一次,键盘会变黑, View 定位会无可挽回地困惑。这是问题的照片,代码在下面,提前致谢![keyboard is gone, no way to slide the view down to correct position ] 1

    override func viewDidLoad() {
super.viewDidLoad()

emailTextField.delegate = self
passwordTextField.delegate = self
verifyPasswordTextField.delegate = self

emailTextField.autocorrectionType = UITextAutocorrectionType.No

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
}


// method to move the view up when keyboard appears
func keyboardWillShow(notification: NSNotification) {

if viewIsLifted == false {

if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {

// hide the logo and name when view slides up
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

self.likemojiIcon.alpha = 0
self.likemojiLabel.alpha = 0

}, completion: nil)

self.view.frame.origin.y -= keyboardSize.height
viewIsLifted = true
}
}
}


// method to slide view back down when keyboard is resigned
func keyboardWillHide(notification: NSNotification) {

if viewIsLifted == true {

if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {

// make logo and name reappear on slide back down
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

self.likemojiIcon.alpha = 1
self.likemojiLabel.alpha = 1

}, completion: nil)

self.view.frame.origin.y += keyboardSize.height
viewIsLifted = false
}
}
}

最佳答案

当您收到键盘出现的通知时关闭用户交互(beginIgnoringInteractionEvents),然后重新打开(endIgnoringInteractionEvents)当您收到键盘确实出现的通知时。

关于ios - 如果用户双击文本字段,键盘会变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33680607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com