Created
March 25, 2014 15:19
-
-
Save mbcrump/9764032 to your computer and use it in GitHub Desktop.
Telerik Animation ViewController.m File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// TelerikAnimations | |
// | |
// Created by Michael Crump on 3/25/14. | |
// Copyright (c) 2014 Michael Crump. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController { | |
UIDynamicAnimator *_animator; | |
NSMutableArray *_points; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[NSTimer scheduledTimerWithTimeInterval:5.0 | |
target:self | |
selector:@selector(theAction) | |
userInfo:nil | |
repeats:NO]; | |
_points = [[NSMutableArray alloc] init]; | |
for (int i=0; i<10; i++) { | |
[_points addObject:[[TKChartDataPoint alloc] initWithX:@(i) Y:@(arc4random()%300)]]; | |
} | |
TKChartLineSeries *lineSeries = [[TKChartLineSeries alloc] initWithItems:_points]; | |
lineSeries.selectionMode = TKChartSeriesSelectionModeDataPoint; | |
lineSeries.style.pointShape = [[TKPredefinedShape alloc] initWithType:TKShapeTypeCircle andSize:CGSizeMake(15, 15)]; | |
lineSeries.style.shapeMode = TKChartSeriesStyleShapeModeAlwaysShow; | |
[_chartView addSeries: lineSeries]; | |
_chartView.yAxis.style.labelStyle.textHidden = YES; | |
_chartView.allowAnimations = YES; | |
[_chartView reloadData]; | |
} | |
-(void) theAction { | |
[self applyGravityEffectAfterTimer]; | |
} | |
- (void)applyGravityEffectAfterTimer | |
{ | |
_animator = [[UIDynamicAnimator alloc] initWithReferenceView:_chartView.plotView]; | |
NSArray *points = [_chartView visualPointsForSeries:_chartView.series[0]]; | |
UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:points]; | |
collision.translatesReferenceBoundsIntoBoundary = YES; | |
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:points]; | |
gravity.gravityDirection = CGVectorMake(0.f, 2.f); | |
UIDynamicItemBehavior *dynamic = [[UIDynamicItemBehavior alloc] initWithItems:points]; | |
dynamic.elasticity = 0.5f; | |
[_animator addBehavior:dynamic]; | |
[_animator addBehavior:gravity]; | |
[_animator addBehavior:collision]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment