如何在iOS图表中轻松突出显示动画

问题描述 投票:0回答:1

当突出显示PieChartView的一部分(来自iOS Charts)时,突出显示的选项默认跳出而不带动画。有没有办法在标准和高亮效果之间简化动画?

标准外观:

突出的外观

ios swift animation ios-charts
1个回答
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)
}
© www.soinside.com 2019 - 2024. All rights reserved.