所选段的大小由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)
}