Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.36 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to do 'serial' animation with GCD?
  2. //customView.alpha = 1.0 here
  3. [UIView animateWithDuration:1 animations:^{
  4.                                   customView.alpha = 0.3;
  5.                               }
  6.                               completion:^(BOOL finished){
  7.                                   // remove customView from super view.
  8.                               }];
  9.        
  10. //(dispatch_queue_t)queue was created in other parts of the code
  11. dispatch_sync(queue, ^{
  12.     [UIView animationWithDuration:animations:...];
  13. });
  14.        
  15. - (void)methodThatIsRunWhenTheNotificationIsReceived {
  16.     // Do other stuff here I assume...
  17.     self.numberOfTimesToRunAnimation = self.numberOfTimesToRunAnimation + 1;
  18.     if ([self.numberOfTimesToRunAnimation == 1]) {
  19.         [self methodThatAnimates];
  20.     }
  21. }
  22.  
  23. - (void)methodThatAnimates {
  24.     if (self.numberOfTimesToRunAnimation > 0) {
  25.         // Animation preparations ...
  26.         [UIView animateWithDuration:1
  27.                          animations:^{
  28.                                   customView.alpha = 0.3;
  29.                          }
  30.                          completion:^(BOOL finished){
  31.                                   // Animation clean up ...
  32.                                   self.numberOfTimesToRunAnimation = self.numberOfTimesToRunAnimation - 1;
  33.                                   [self methodThatAnimates];
  34.                          }];
  35.     }
  36. }