gpt4 book ai didi

ios - 键盘打开时移动菜单(快速)

转载 作者:行者123 更新时间:2023-12-01 21:59:49 27 4
gpt4 key购买 nike

我的函数“keyboardWillShown”有问题。所以我想要的是菜单打开时,菜单正好出现在键盘上方。它可以在Iphone 8 plus,8、7、6上完美运行。但是,当我在模拟器上运行Iphone 11时,结果如下。

Picture of how it looks in Iphone 11

Constrains

这是我的代码:

@objc func keyboardWillShown(notification: NSNotification) {
let info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue

UIView.animate(withDuration: 0.1, animations: { () -> Void in
self.keyboardConstrains.constant = keyboardFrame.size.height
})
}

通话功能
override func viewWillAppear(_ animated: Bool) {
NotificationCenter.default.addObserver( self, selector: #selector(keyboardWillShown(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil )
}

override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver( self,name: UIResponder.keyboardWillShowNotification, object: nil )
}

最佳答案

您可以根据屏幕尺寸设置约束

if self.view.height >= 800{ //For bigger screens (X ,11)
self.keyboardConstrains.constant = keyboardFrame.size.height - 50
} else {
self.keyboardConstrains.constant = keyboardFrame.size.height
}

关于ios - 键盘打开时移动菜单(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60337511/

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