[英]Animating Auto Layout Constraints Not Working
iOS 10,Swift 3.1
我要设置动画的UITableViewCell
中有一个名为graphPopup
的UIView
。 基本上,当有人点击图形时,会出现一个弹出窗口,我希望它将其x
和y
设置为动画。
除了弹出窗口的动画外,其他所有东西都在工作。 现在是这样的:
我希望弹出窗口从点到点滑动到适当位置。 这是我的代码:
class TotalCell: UITableViewCell, ChartViewDelegate{
@IBOutlet weak var graphPopup: UIView!
@IBOutlet weak var popupConstraintY: NSLayoutConstraint!
@IBOutlet weak var popupConstraintX: NSLayoutConstraint!
func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
//...
graphPopup.isHidden = false
//Set new auto layout constraints
self.popupConstraintX.constant = highlight.xPx-44
self.popupConstraintY.constant = highlight.yPx+18
//Animate (which does nothing)
UIView.animate(withDuration: 1.0, animations: {
self.graphPopup.layoutIfNeeded()
})
}
}
知道我做错了什么吗? 如果我完全删除动画位,它的行为方式相同,但是我知道正在调用动画。
有任何想法吗?
尝试使用self.layoutIfNeeded()
而不是self.graphPopup.layoutIfNeeded()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.