The answer is likely that I just can’t mix things the way I’m trying to, and I’ll accept “the right way” to mix things (probably a more complicated CAAnimation? I don’t know). What I have:
__block BOOL animationComplete = FALSE;
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationCurveEaseInOut
animations:^{
[self setFrame:destRect];
}
completion:^(BOOL finished) {
animationComplete = YES;
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}];
Which is then polled with:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, (unsigned long)NULL), ^{
while (!animationComplete) {
CALayer *layer = self.layer.presentationLayer;
CGRect frame = [layer frame];
CGPoint point = [layer position];
float currentTranslation = [[layer valueForKeyPath:@"transform.translation.x"] floatValue];
NSLog(@"%.1f : %.1f : %.1f : %.1f : %.1f : %.1f",frame.origin.x, currentTranslation, frame.origin.x, layer.bounds.origin.x, layer.position.x, point.x);
}
});
Am I grabbing the wrong queue? The wrong parameter? Am I looking at the wrong layer? Above is a scattershot of values I’ve tried looking at, all unchanging during the animation….
214.4 : 0.0 : 214.4 : 0.0 : 264.4 : 264.4
214.4 : 0.0 : 214.4 : 0.0 : 264.4 : 264.4
214.4 : 0.0 : 214.4 : 0.0 : 264.4 : 264.4
214.4 : 0.0 : 214.4 : 0.0 : 264.4 : 264.4
214.4 : 0.0 : 214.4 : 0.0 : 264.4 : 264.4
etc. 🙂
You can only interact with the view hierarchy on the main thread. You should not be calling
self.layeron a global dispatch queue. You can only do that ondispatch_get_main_queue().You will have to rewrite your logging to not loop like that, since the completion block also runs on the main thread, and it can’t run if your block is running.
UPDATE
The problem is definitely caused by accessing the layer from a non-main thread. I made a test project with a view subclass,
MyView. I gave it this method:When this method ran, I got output like this:
… and so on, with the X values eventually reaching 280.
I then commented out the
dispatch_syncline, so the layer access and logging happens on the global low-priority thread, and I got output like this:… and so on, with the X values never changing.