gpt4 book ai didi

ios - UIKeyboardWillHideNotification 动画延迟

转载 作者:行者123 更新时间:2023-11-28 06:37:50 26 4
gpt4 key购买 nike

我已经注册了两个 UIKeyboardNotifications(keyboardWillShow 和 keyboardWillHide)并且都被触发了。当文本字段移回原始位置的动画仅在键盘消失后才被触发时,问题就出现了。有没有办法减少获取通知和动画文本字段之间的延迟?

func keyboardWillShow(notification: NSNotification) {
let info = notification.userInfo!
let keyboardFrame : CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
duration = (info[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue)
let rawAnimationCurve = (notification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).unsignedIntValue << 16
animationCurve = UIViewAnimationOptions(rawValue: UInt(rawAnimationCurve))
let moveAmount = keyboardFrame.height
UIView.animateWithDuration(duration!, delay:0, options: animationCurve, animations: {
self.txtfield.transform = CGAffineTransformMakeTranslation(0.0, -self.moveAmount)
}, completion:nil)
}

func keyboardWillHide(notification: NSNotification) {
UIView.animateWithDuration(duration, delay:0, options:animationCurve, animations: {
self. txtfield.transform = CGAffineTransformMakeTranslation(0.0, 0.0)
}, completion:nil)
}

GIF image here

最佳答案

意识到一个问题,是我粗心的错误。

添加:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(viewController.keyboardDidHide), name: UIKeyboardWillHideNotification, object: nil)

代替:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(viewController.keyboardWillHide), name: UIKeyboardWillHideNotification, object: nil)

关于ios - UIKeyboardWillHideNotification 动画延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38697215/

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