动画效果自动布局约束不工作
问题描述:
iOS的10,雨燕3.1动画效果自动布局约束不工作
我有一个名为UIView
一个graphPopup
是UITableViewCell
我试图动画里面。基本上,当有人点击一个图表时,出现一个弹出窗口,我希望它将其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()
。
有两个问题 - 您是否尝试过在'self'上调用'layoutIfNeeded()',放入'graphPopup'?第二 - 你在哪里隐藏弹出窗口?你有没有试图保持它始终可见?这很奇怪,但也许动画发生时,它不可见? – Losiowaty