如何在Core Plot中为条形图的外观设置动画? [英] How do I animate the appearance of a bar chart in Core Plot?

查看:85
本文介绍了如何在Core Plot中为条形图的外观设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当首次使用Core Plot显示条形图时,我希望条形图向上生长,直到它们达到正确的高度。

When first displaying a bar chart using Core Plot, I'd like the bars to grow upward until they reach their correct heights.

你会如何使用这个框架创建这样的动画?

How would you create such an animation using this framework?

推荐答案

这就是我做的:


  1. 在我的viewDidLoad控制器的方法中,我创建了CPTXYGraph:

  1. In my viewDidLoad controller's method I created the CPTXYGraph:

graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];


  • 我在空图中添加了动画:

  • I added animation to the empty graph:

    CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    


  • 然后在animationDidStop委托的方法中,我将绘图数据和动画添加到图表中:

  • Then in animationDidStop delegate's method I added the plot data and animation to the graph:

    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
    [anim setDuration:2.0f];
    
    anim.toValue = [NSNumber numberWithFloat:1.0f];
    anim.fromValue = [NSNumber numberWithFloat:0.0f];
    anim.removedOnCompletion = NO;
    anim.delegate = self;
    anim.fillMode = kCAFillModeForwards;
    
    gPlot.anchorPoint = CGPointMake(0.0, 0.0);
    
    [gPlot addAnimation:anim forKey:@"grow"];
    
    [graph addPlot:gPlot ];// IMPORTANT here I added the plot data to the graph :) .
    


  • 这篇关于如何在Core Plot中为条形图的外观设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆