gpt4 book ai didi

ios - 当键盘出现在我的应用程序中时,按钮部分向上移动(只有按钮的文本移动)

转载 作者:搜寻专家 更新时间:2023-11-01 07:18:03 24 4
gpt4 key购买 nike

我的 swift 应用程序中有一个按钮,它位于屏幕底部。它的约束条件是:

enter image description here

我还附加了 socket 以将我的按钮与屏幕底部分开:

enter image description here

当我运行该应用程序时,我看到了我的按钮(我添加了一些背景颜色以便我的示例清晰可见):

enter image description here

现在,奇怪的事情发生了——当键盘显示时,按钮上的文字向上移动,蓝色背景保持原样:

enter image description here

而且按钮的可见部分根本不可点击。

是我的实现中的某种错误还是问题?

我的代码非常简单:

@IBOutlet weak var continueUsernameBottomConstraint: NSLayoutConstraint!

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)


NotificationCenter.default.addObserver(self, selector: #selector(tutorialKeyboardWillAppear), name: .UIKeyboardWillShow, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(tutorialKeyboardWillDisappear), name: .UIKeyboardWillHide, object: nil)

}


func tutorialKeyboardWillAppear(notification: NSNotification){
print("KEYBOARD APPEARS")
let endFrame = ((notification as NSNotification).userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue

continueUsernameBottomConstraint.constant = view.bounds.height - endFrame.origin.y

self.view.layoutIfNeeded()
}

func tutorialKeyboardWillDisappear(notification: NSNotification){

print("KEYBOARD DISAPPEARS")
let endFrame = ((notification as NSNotification).userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue

continueUsernameBottomConstraint.constant = view.bounds.height - endFrame.origin.y

self.view.layoutIfNeeded()

}

最佳答案

使用这个

func tutorialKeyboardWillAppear(notification: NSNotification){
print("KEYBOARD APPEARS")
let endFrame = ((notification as NSNotification).userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
continueUsernameBottomConstraint.constant = continueUsernameBottomConstraint.constant + CGFloat(endFrame.height)
self.view.layoutIfNeeded()
}

func tutorialKeyboardWillDisappear(notification: NSNotification){

print("KEYBOARD DISAPPEARS")
let endFrame = ((notification as NSNotification).userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
continueUsernameBottomConstraint.constant = continueUsernameBottomConstraint.constant - CGFloat(endFrame.height)
self.view.layoutIfNeeded()

}

关于ios - 当键盘出现在我的应用程序中时,按钮部分向上移动(只有按钮的文本移动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40830410/

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