title: Force Animation Completion Block to Run on Background Thread to Signal Semaphore
body: <p>Hi so I'm trying to signal a semaphore from within a an animation completion block, but because the main thread is blocked by the semaphore, the completion block never even gets fired.</p>
  
  <p>The signal cannot be called within the animation block as it will be called too soon.</p>
  
  <p>I have tried wrapping the entire UIView animation block asynchronously in a background thread but that does not prevent the completion block from being dispatched to the main queue.</p>
  
  <pre><code>-(void)performAnimation {
      dispatch_semaphore_t sema = dispatch_semaphore_create(0);
  
      [UIView animateWithDuration:1.0 animations:^{
          // animation code   
      } completion: ^{
          dispatch_semaphore_signal(sema);
      }];
  
      dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
  }
  </code></pre>
  
  <p>Thank you in advanced!</p>