我有第一个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/