31. En pratique
Déclencher une animation d’attente avant de
bloquer le main thread
[activityIndicator startAnimating];
[self doReallyLongStuff];
32. En pratique
Déclencher une animation d’attente avant de
bloquer le main thread
[activityIndicator startAnimating];
[CATransaction flush];
[self doReallyLongStuff];
33. En pratique
Appliquer des animations implicites à des
layers qui viennent d’être ajoutés
CALayer* layer = [CALayer layer];
layer.frame = CGRectMake(0, 0, 200, 200);
layer.backgroundColor = [[UIColor redColor] CGColor];
[self.view.layer addSublayer:layer];
layer.frame = CGRectMake(100, 100, 200, 200);
34. En pratique
Appliquer des animations implicites à des
layers qui viennent d’être ajoutés
CALayer* layer = [CALayer layer];
layer.frame = CGRectMake(0, 0, 200, 200);
layer.backgroundColor = [[UIColor redColor] CGColor];
[self.view.layer addSublayer:layer];
[CATransaction flush];
layer.frame = CGRectMake(100, 100, 200, 200);
35. En pratique
Faire un rendu dans un contexte en
background et nettoyer derrière soi
CALayer* layer = ...;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
UIGraphicsBeginImageContext(layer.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[layer renderInContext:context];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_sync(dispatch_get_main_queue(), ^{
[self useImage:image];
});
});
36. En pratique
Faire un rendu dans un contexte en
background et nettoyer derrière soi
CALayer* layer = ...;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
UIGraphicsBeginImageContext(layer.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[layer renderInContext:context];
[CATransaction flush];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_sync(dispatch_get_main_queue(), ^{
[self useImage:image];
});
});
37. En pratique ?
Faire un rendu dans un contexte en
background et nettoyer derrière soi
CALayer* layer = ...;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
[CATransaction lock];
UIGraphicsBeginImageContext(layer.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[layer renderInContext:context];
[CATransaction unlock];
[CATransaction flush];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_sync(dispatch_get_main_queue(), ^{
[self useImage:image];
});
});