如何为核心情节数据标签添加动画?

how to add animation for core plot datalabel?

我想要用户点击按钮时的效果。条形图中的数据标签在动画中消失。将 alpha 值从 1 更改为 0。

这就是我想要做的:

[UIView animateWithDuration:0.5
                      delay:1.0
                    options: UIViewAnimationCurveEaseOut
                 animations:^{
                     [self.hostingView.hostedGraph.allPlots firstObject].showLabels = showLabel;
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];
}

但是动画不显示。有什么建议吗?

UIView 动画将不起作用,因为 Core Plot 是建立在 Core Animation 图层上的。数据标签列表对绘图是私有的,但它们使用核心绘图注释显示。该图的 annotations 属性 为您提供了附加到该图的所有注释的数组。遍历数组并将所需的动画应用于每个注释的 contentLayer。如果您在绘图上有其他注释,请务必检查以确保您只是在动画化数据标签。每个 CPTLayer 都有一个 identifier 属性 可用于标识您创建的注释。