突出显示PieChartView的一部分时(来自iOS Charts),突出显示的选择默认情况下会跳出而不显示动画。有没有一种方法可以减轻标准效果和突出显示效果之间的动画影响?
标准外观:
突出显示的外观
答案 0 :(得分:0)
所选段的大小由dataSet的selectionShift
属性控制。值0
表示选中该元素不会对其进行更改。
可以通过内置的动画器功能控制该值随时间的变化。
要在选择饼图的一部分时触发动画制作器,请实现图表视图委托的chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight)
功能。
示例:
override func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
let animator = Animator()
animator.updateBlock = {
// Usually the phase is a value between 0.0 and 1.0
// Multiply it so you get the final phaseShift you want
let phaseShift = 10 * animator.phaseX
let dataSet = chartView.data?.dataSets.first as? PieChartDataSet
// Set the selectionShift property to actually change the selection over time
dataSet?.selectionShift = CGFloat(phaseShift)
// In order to see the animation, trigger a redraw every time the selectionShift property was changed
chartView.setNeedsDisplay()
}
// Start the animation by triggering the animate function with any timing function you like
animator.animate(xAxisDuration: 0.3, easingOption: ChartEasingOption.easeInCubic)
}