This is a migrated thread and some comments may be shown as answers.

chart size change animation

1 Answer 102 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oleg
Top achievements
Rank 1
Oleg asked on 05 Jan 2015, 07:43 AM
when i try to animate a size change of the chart it just changes to the final value without animation, every thing else (background and other views) changes animated but the chart is not.
I tried 3 different ways to animate:

1.Constraints:
     widthConstraint.constant = 200;
     heightConstarint.constant=200;

    [UIView animateWithDuration:0.5 animations:^{
          [self.view layoutIfNeeded];
    }];

2. Frame change:
      [UIView animateWithDuration:0.5 animations:^{
          _chart.bounds = CGRectMake(0, 0, 200, 200);
      }];

3. Layer change:

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
    animation.duration = 0.5;
    animation.toValue = [NSValue valueWithCGSize:CGSizeMake(200, 200)];
    [_chart.layer addAnimation:animation forKey:@"sizeAnimation"];


Help.
  















1 Answer, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 06 Jan 2015, 08:11 AM
Hi Oleg,

Thank you for contacting us.

TKChart is a complex view containing other subviews and sublayers in its hierarchy. The reason for the issue you have is that when you change the chart's frame in the animations block, TKChart's layoutSubviews method is called. It uses the chart's final frame to calculate and layout its subviews, which makes it look like the chart is not animating. A better approach to achieve similar animation is to use UIView's transform property. Please consider the following snippet:
- (void)viewDidLoad {
   //...
 
    chart.transform = CGAffineTransformMakeScale(0, 0);
 
   //...
}
 
- (void)viewDidAppear:(BOOL)animated
{
    chart.clipsToBounds = YES;
    [UIView animateWithDuration:2.
                          delay:0
                        options:0
                     animations:^{
                         chart.transform = CGAffineTransformIdentity;
                     }
                     completion:nil];
}

I hope this helps. Should you have further questions, do not hesitate to contact us.

Regards,
Adrian
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart
Asked by
Oleg
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Share this question
or