Richard Cheung
Richard Cheung

Reputation: 1

add an animation to bar plot does not take effect visually

I am a newer to core plot. And recently I decide to add bar growth animation to my plot. so I followed the instruction searched here to implement the animation. Now I come up with the problem: the animation seemed not to take effect.The delegate: didStopAnimate:(BOOL) returns no matter how long I set the duration of the animation with flag false. One more thing to state: in the graph view, I put a scrollview under the real graph hosting view. does that affect Core animation to work? the plot appeared after a navigation from the table view to itself. here is some of my codes:

        if ([plot_type isEqualToString:@"bar"]) {
        CPTBarPlot *plot = [[CPTBarPlot alloc] init];
        //id
        plot.identifier = [d objectForKey:@"title"];
        plot.title = [d objectForKey:@"title"];
        plot.lineStyle = barLineStyle;
        plot.barCornerRadius = 1.2;
        //set color
        CPTGradient *gradient = [CPTGradient gradientWithBeginningColor:[CPTColor colorWithCGColor:color_begin] endingColor:[CPTColor colorWithCGColor:color_end]];
        gradient.angle = 90.0f;
        CPTFill *fill = [CPTFill fillWithGradient:gradient];
        plot.fill  = fill;


        //bar width
        double width = [[d objectForKey:@"width"] doubleValue]==0.0?0.6:[[d objectForKey:@"width"] doubleValue];
        plot.barWidth = CPTDecimalFromFloat(width);
        plot.barsAreHorizontal = NO;
        //need manually stacked
        if (need_stack && !is_first) {
            plot.barBasesVary = YES;
        } else {
            plot.barBasesVary = NO;
        }
        //data source
        plot.dataSource = self;
        //delegate
        plot.delegate = self;

        CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];
        [anim setDuration:2.0f];
        anim.toValue = [NSNumber numberWithFloat:1];
        anim.fromValue = [NSNumber numberWithFloat:0.0f];
        anim.removedOnCompletion = NO;
        anim.delegate = self;
        anim.fillMode = kCAFillModeForwards;
        [plot addAnimation:anim forKey:(NSString *)plot.identifier];

        [graph addPlot:plot toPlotSpace:plotSpace];
    }

Thanks for your helps in advance.

Upvotes: 0

Views: 215

Answers (1)

Eric Skroch
Eric Skroch

Reputation: 27381

The transform property of a CALayer is CATransform3D struct, not a scalar value. You should wrap it using the NSValue method +valueWithCATransform3D:.

Upvotes: 1

Related Questions