gpt4 book ai didi

ios - UI KeyboardWillShowNotification 中的栏按钮项目动画

转载 作者:行者123 更新时间:2023-11-30 13:43:53 25 4
gpt4 key购买 nike

我不知道出了什么问题。我的导航栏中有 2 个右侧按钮,当键盘打开时,我需要 A 和 B 按钮,当键盘关闭时,我需要 A 和 C,或者可能只是 C。我这样做了。我使用 UIKeyboardWillShowNotification 来检查键盘何时打开或关闭。

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

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

效果很好。问题是当我调用方法“KeyboardWillShow”和“KeyboardWillHide”时,右侧按钮会飞进来。请参见此处:GIF

 func keyboardWillShow(sender: NSNotification) {
if let userInfo = sender.userInfo {
if let keyboardHeight = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.size.height {
textViewBottomConstraint.constant = keyboardHeight
print("keyboard is shown")

self.navigationItem.rightBarButtonItems = nil
let rightButtons : NSArray = [self.keyboardRightButton, self.cameraRightButton]
self.navigationItem.setRightBarButtonItems(rightButtons as? [UIBarButtonItem], animated: true)

UIView.animateWithDuration(0.1, animations: { () -> Void in
self.view.layoutIfNeeded()

})
}
}


}

我尝试过这个,它工作正常,但仅限于关闭键盘时。

func dismissKeyboard()
{

composeTextView.resignFirstResponder()

self.navigationItem.rightBarButtonItems = nil
self.navigationItem.setRightBarButtonItem(settingsRightButton, animated: false)

最佳答案

解决方法:

    func textViewShouldBeginEditing(textView: UITextView) -> Bool
{

self.navigationItem.rightBarButtonItems = nil
let rightButtons : NSArray = [self.keyboardRightButton, self.cameraRightButton]
self.navigationItem.setRightBarButtonItems(rightButtons as? [UIBarButtonItem], animated: true)

return true
}

谢谢

关于ios - UI KeyboardWillShowNotification 中的栏按钮项目动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35214307/

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