gpt4 book ai didi

ios - 带有持续时间的 UIView.animate 无法正常工作

转载 作者:行者123 更新时间:2023-11-28 23:28:36 24 4
gpt4 key购买 nike

UIView.animate 在我的代码的“else”部分不起作用。但是,它在“if”语句中工作得很好。有什么建议可能导致此问题吗?

    if notification.name == UIResponder.keyboardWillShowNotification ||
notification.name == UIResponder.keyboardWillChangeFrameNotification {

// Keyboard shows
self.view.layoutIfNeeded()
UIView.animate(withDuration: 0.25) {
self.view.layoutIfNeeded()
let heightHelper = self.bottomConstraint.constant
self.bottomConstraint.constant = keyboardRect.height + 20

self.bottomConstraintEmail.constant += keyboardRect.height + 20 - heightHelper
self.anmeldenLabel.alpha = 0
self.logoConstraint.constant = 45
}
} else {
// Keyboard hides
self.view.layoutIfNeeded()
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
self.bottomConstraintEmail.constant = 337
self.bottomConstraint.constant = 255.5
self.logoConstraint.constant = 60
self.anmeldenLabel.alpha = 1
}
}

最佳答案

@Don 完全正确:layoutIfNeeded() 应该在设置新约束后调用。

这应该可以正常工作:

if notification.name == UIResponder.keyboardWillShowNotification ||
notification.name == UIResponder.keyboardWillChangeFrameNotification {

// Keyboard shows
let heightHelper = self.bottomConstraint.constant
self.bottomConstraint.constant = keyboardRect.height + 20

self.bottomConstraintEmail.constant += keyboardRect.height + 20 - heightHelper
self.anmeldenLabel.alpha = 0
self.logoConstraint.constant = 45

UIView.animate(withDuration: 0.25) {
self.view.layoutIfNeeded()
}
} else {
// Keyboard hides
self.bottomConstraintEmail.constant = 337
self.bottomConstraint.constant = 255.5
self.logoConstraint.constant = 60
self.anmeldenLabel.alpha = 1

UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
}

关于ios - 带有持续时间的 UIView.animate 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57648757/

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