Showing
1 changed file
with
20 additions
and
6 deletions
| @@ -181,8 +181,8 @@ | @@ -181,8 +181,8 @@ | ||
| 181 | - (void)setChartData:(NSArray *)data | 181 | - (void)setChartData:(NSArray *)data |
| 182 | { | 182 | { |
| 183 | if (data != _chartData) { | 183 | if (data != _chartData) { |
| 184 | - CGFloat yFinilizeValue , xFinilizeValue; | 184 | + __block CGFloat yFinilizeValue , xFinilizeValue; |
| 185 | - CGFloat yValue , xValue; | 185 | + __block CGFloat yValue , xValue; |
| 186 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; | 186 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; |
| 187 | pathAnimation.duration = _duration; | 187 | pathAnimation.duration = _duration; |
| 188 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | 188 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; |
| @@ -191,6 +191,10 @@ | @@ -191,6 +191,10 @@ | ||
| 191 | pathAnimation.fillMode = kCAFillModeForwards; | 191 | pathAnimation.fillMode = kCAFillModeForwards; |
| 192 | self.layer.opacity = 1; | 192 | self.layer.opacity = 1; |
| 193 | 193 | ||
| 194 | + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
| 195 | + [NSThread sleepForTimeInterval:1]; | ||
| 196 | + // update UI on the main thread | ||
| 197 | + dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 194 | for (PNScatterChartData *chartData in data) { | 198 | for (PNScatterChartData *chartData in data) { |
| 195 | for (NSUInteger i = 0; i < chartData.itemCount; i++) { | 199 | for (NSUInteger i = 0; i < chartData.itemCount; i++) { |
| 196 | yValue = chartData.getData(i).y; | 200 | yValue = chartData.getData(i).y; |
| @@ -207,6 +211,8 @@ | @@ -207,6 +211,8 @@ | ||
| 207 | [self.pathLayer addAnimation:pathAnimation forKey:@"fade"]; | 211 | [self.pathLayer addAnimation:pathAnimation forKey:@"fade"]; |
| 208 | } | 212 | } |
| 209 | } | 213 | } |
| 214 | + }); | ||
| 215 | + }); | ||
| 210 | } | 216 | } |
| 211 | } | 217 | } |
| 212 | 218 | ||
| @@ -313,11 +319,17 @@ | @@ -313,11 +319,17 @@ | ||
| 313 | } | 319 | } |
| 314 | 320 | ||
| 315 | - (void) drawLineFromPoint : (CGPoint) startPoint ToPoint : (CGPoint) endPoint WithLineWith : (CGFloat) lineWidth AndWithColor : (UIColor*) color{ | 321 | - (void) drawLineFromPoint : (CGPoint) startPoint ToPoint : (CGPoint) endPoint WithLineWith : (CGFloat) lineWidth AndWithColor : (UIColor*) color{ |
| 322 | + | ||
| 323 | + // call the same method on a background thread | ||
| 324 | + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
| 325 | + [NSThread sleepForTimeInterval:2]; | ||
| 316 | // calculating start and end point | 326 | // calculating start and end point |
| 317 | - CGFloat startX = [self mappingIsForAxisX:true WithValue:startPoint.x]; | 327 | + __block CGFloat startX = [self mappingIsForAxisX:true WithValue:startPoint.x]; |
| 318 | - CGFloat startY = [self mappingIsForAxisX:false WithValue:startPoint.y]; | 328 | + __block CGFloat startY = [self mappingIsForAxisX:false WithValue:startPoint.y]; |
| 319 | - CGFloat endX = [self mappingIsForAxisX:true WithValue:endPoint.x]; | 329 | + __block CGFloat endX = [self mappingIsForAxisX:true WithValue:endPoint.x]; |
| 320 | - CGFloat endY = [self mappingIsForAxisX:false WithValue:endPoint.y]; | 330 | + __block CGFloat endY = [self mappingIsForAxisX:false WithValue:endPoint.y]; |
| 331 | + // update UI on the main thread | ||
| 332 | + dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 321 | // drawing path between two points | 333 | // drawing path between two points |
| 322 | UIBezierPath *path = [UIBezierPath bezierPath]; | 334 | UIBezierPath *path = [UIBezierPath bezierPath]; |
| 323 | [path moveToPoint:CGPointMake(startX, startY)]; | 335 | [path moveToPoint:CGPointMake(startX, startY)]; |
| @@ -334,6 +346,8 @@ | @@ -334,6 +346,8 @@ | ||
| 334 | animateStrokeEnd.toValue = [NSNumber numberWithFloat:1.0f]; | 346 | animateStrokeEnd.toValue = [NSNumber numberWithFloat:1.0f]; |
| 335 | [shapeLayer addAnimation:animateStrokeEnd forKey:nil]; | 347 | [shapeLayer addAnimation:animateStrokeEnd forKey:nil]; |
| 336 | [self.layer addSublayer:shapeLayer]; | 348 | [self.layer addSublayer:shapeLayer]; |
| 349 | + }); | ||
| 350 | + }); | ||
| 337 | } | 351 | } |
| 338 | 352 | ||
| 339 | @end | 353 | @end |
-
Please register or login to post a comment