Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created August 17, 2013 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfix/6259117 to your computer and use it in GitHub Desktop.
Save rayfix/6259117 to your computer and use it in GitHub Desktop.
Our animations were not working with our dispatch queue. I boiled it down to a simple test case. However, the test case works perfectly as expected so there is another problem that is happening. This code makes a view oscillate back and forth.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self move];
}
- (void)move
{
static BOOL flipFlop;
dispatch_queue_t computeQueue = dispatch_queue_create("worker.queue", NULL);
dispatch_async(computeQueue, ^{
CGPoint point = [self computePoint:flipFlop];
flipFlop = !flipFlop;
dispatch_sync(dispatch_get_main_queue(), ^{
[self moveTo:point];
});
});
}
- (CGPoint)computePoint:(BOOL)flipFlop
{
return flipFlop ? CGPointMake(300, 300) : CGPointMake(10, 10);
}
- (void)moveTo:(CGPoint)point
{
CGRect targetFrame = self.graphicView.frame;
targetFrame.origin = point;
[UIView animateWithDuration:1
animations:^{
self.graphicView.frame = targetFrame;
}
completion:^(BOOL finished) {
[self move];
}
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment