[英]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.