Created
August 17, 2013 23:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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