gpt4 book ai didi

ios - swift:在 ViewController 返回后显示动画

转载 作者:行者123 更新时间:2023-11-30 11:17:28 31 4
gpt4 key购买 nike

我有第一个ViewController和第二个ViewController。当我从第二个 ViewController 返回到第一个 ViewController 时,我想在第一个 ViewController 中显示按钮。

要返回,我使用以下代码:

self.dismiss(animated: true, completion: nil)

此代码用于在第一个 ViewController 中显示按钮

@IBOutlet weak var infoButton: UIButton!
@IBOutlet weak var nextButton: UIButton!

@IBOutlet weak var infoButtonTopConstraint: NSLayoutConstraint!
@IBOutlet weak var nextButtonBottomConstraint: NSLayoutConstraint!
@IBOutlet weak var infoButtonHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var nextButtonHeightConstraint: NSLayoutConstraint!

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)

showButtonAnimation()
//animaton()
}

func showButtonAnimation() {

self.infoButtonTopConstraint.constant += self.infoButtonHeightConstraint.constant
self.nextButtonBottomConstraint.constant -= self.nextButtonHeightConstraint.constant

UIView.animate(withDuration: 1.0, delay: 0.0,
options: [], animations: {
self.view.layoutIfNeeded()

})
}

但是当我从第二个 ViewController 返回时,按钮没有显示。

最佳答案

替换这个

func showButtonAnimation() {
self.view.layoutIfNeeded()
UIView.animate(withDuration: 1.0, delay: 0.0,
options: [], animations: {
self.infoButtonTopConstraint.constant += self.infoButtonHeightConstraint.constant
self.nextButtonBottomConstraint.constant -= self.nextButtonHeightConstraint.constant
self.view.layoutIfNeeded()

})
}

编辑 1

viewWillAppear 未调用原因:您将第二个 viewController 呈现为 overCurrentContext modalPresentationStyle

只需将 overCurrentContext 替换为 fullScreen 即可。

关于ios - swift:在 ViewController 返回后显示动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51605669/

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