【发布时间】:2017-08-12 18:49:22
【问题描述】:
我有一个UIViewController,每次点击UITabBarButtonItem 时都会触发它。问题是它有点像菜单,由一个从屏幕底部向上滑动的UIView 组成。
现在,最初,底部约束设置为 -500,因此它不在屏幕上。我创建了一个函数,通过一些动画将约束设置回 100。问题是我认为如果我在viewWillAppear() 中调用该函数,它每次都会被动画化。但事实并非如此。我还尝试在viewDidDisappear() 中将约束重置回-500,以便在下次触发之前它在屏幕外。
不起作用。它只是第一次工作。我错过了一些东西,或者我在错误的地方调用它......
class PostVC: UIViewController {
@IBOutlet weak var menuBottomConstraint: NSLayoutConstraint!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
animateMenu()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
menuBottomConstraint.constant = -500
}
func animateMenu() {
menuBottomConstraint.constant = 100
UIView.animate(
withDuration: 1.0,
delay: 0.0,
usingSpringWithDamping: 0.5,
initialSpringVelocity: 0.0, options: .curveEaseOut,
animations: {
self.view.layoutIfNeeded()
},
completion: nil
)
}
}
【问题讨论】:
-
不相关,但在调用
super.viewWill[Disa|A]ppear时不应硬编码true。传递animated参数。
标签: swift uiview uiviewanimation viewwillappear