[英]Animating Auto Layout Constraints Not Working
iOS 10, Swift 3.1 iOS 10,Swift 3.1
I have a UIView
called graphPopup
inside a UITableViewCell
that I'm trying to animate. 我要设置动画的
UITableViewCell
中有一个名为graphPopup
的UIView
。 Basically when someone taps a graph, a popup appears and I'd like it to animate its x
and y
into place. 基本上,当有人点击图形时,会出现一个弹出窗口,我希望它将其
x
和y
设置为动画。
Everything is working except the animation of the popup. 除了弹出窗口的动画外,其他所有东西都在工作。 Here's how it looks now:
现在是这样的:
I want the popup to slide from point-to-point into position. 我希望弹出窗口从点到点滑动到适当位置。 Here is my code:
这是我的代码:
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()
})
}
}
Any idea what I might be doing wrong? 知道我做错了什么吗? If I remove the animation bit entirely, it behaves the same way, but I know the animation is being called.
如果我完全删除动画位,它的行为方式相同,但是我知道正在调用动画。
Any ideas? 有任何想法吗?
尝试使用self.layoutIfNeeded()
而不是self.graphPopup.layoutIfNeeded()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.