【发布时间】:2017-04-06 23:32:20
【问题描述】:
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(),插入graphPopup?第二 - 你在哪里隐藏弹出窗口?你试过让它一直可见吗?这会很奇怪,但也许动画是在不可见的时候发生的?
标签: ios autolayout uiviewanimation ios-charts