Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在Core Plot中设置条形图外观的动画?_Iphone_Ios_Core Plot - Fatal编程技术网

Iphone 如何在Core Plot中设置条形图外观的动画?

Iphone 如何在Core Plot中设置条形图外观的动画?,iphone,ios,core-plot,Iphone,Ios,Core Plot,当第一次使用Core Plot显示条形图时,我希望条形图向上生长,直到达到正确的高度 您将如何使用此框架创建这样的动画?这非常类似于:这就是我所做的: 在viewDidLoad控制器的方法中,我创建了CPTXYGraph: graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds]; 我将动画添加到空图形中: CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWit

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

您将如何使用此框架创建这样的动画?

这非常类似于:

这就是我所做的:

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

    graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
    
  • 我将动画添加到空图形中:

    CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    
  • 然后在animationDidStop委托的方法中,我将绘图数据和动画添加到图形中:

    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 :) .
    

  • 为您的CPTBarPlot添加动画,如下所示:

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    [animation setDuration:1];
    CATransform3D transform = CATransform3DMakeScale(1, 0.0001, 1);
    // offsetY=[PlotDisplayAreaUnderXAxisHeight]-[PlotDisplayAreaHeight]/2
    transform = CATransform3DConcat(transform, CATransform3DMakeTranslation(0, offsetY, 0));
    animation.fromValue = [NSValue valueWithCATransform3D:transform];
    animation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    [barPlot addAnimation:animation forKey:@"barGrowth"];
    

    谢谢Michele的精彩回答

    我已经从她的答案上传了一个示例到Github,供那些想下载演示并立即开始工作的人使用


    享受编码

    像这样添加不透明度动画

    CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeInAnimation.duration = 1.0f;
    fadeInAnimation.removedOnCompletion = NO;
    fadeInAnimation.fillMode = kCAFillModeForwards;
    fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
    [xSquaredPlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];