【发布时间】:2018-06-24 20:22:27
【问题描述】:
除 mainViewConstraint 之外,这段代码的所有动画都很好。我试图通过将 mainViewConstraint 坐标从 -195 转换为 0 来使 mainView 从顶部滑入。不幸的是,它没有从 -195 移动到 0。它只是开始出现在 0。
import UIKit
class FirstViewController: UIViewController {
@IBOutlet weak var bgImage: UIImageView!
@IBOutlet weak var mainView: UIView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var findButton: UIButton!
@IBOutlet weak var mainViewConstraint: NSLayoutConstraint!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
mainViewConstraint.constant = -195
for i in [mainView, titleLabel, findButton] {
i?.alpha = 0
}
UIView.animate(withDuration: 1, animations: {
}) { (true) in
self.animateView()
}
}
func animateView() {
UIView.animate(withDuration: 2, animations: {
self.mainView.alpha = 1
self.mainViewConstraint.constant = 0
self.view.layoutIfNeeded()
}) { (true) in
self.animateLbl()
}
}
func animateLbl() {
UIView.animate(withDuration: 1, animations: {
self.titleLabel.alpha = 1
}) { (true) in
self.animateBtn()
}
}
func animateBtn() {
UIView.animate(withDuration: 1) {
self.findButton.alpha = 1
}
}
}
【问题讨论】:
-
什么是mainViewConstraint??它是 superView 的最高约束吗?
标签: animation swift4 nslayoutconstraint