I am trying to get a better understanding of this topic. Lets say I want to do some really cool animation like the following
- (void)coolAnimation
{
[UIView animateWithDuration: some duration
animations:^{ some animation }];
}
Since its an animation block, does it automatically added to the main_queue ? Or for best practice, I should always add the UI updates into the main_queue like the following.
dispatch_async(dispatch_get_main_queue(), ^{
[self coolAnimation];
});
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:]
. It's best to let the OS run your animations; the animation thread does not block the main thread -- only the animation block itself.
In a very high-level hand-wavy kind of view of this, [UIView animateWithDuration:animations:]
evaluates your block and determines functions for each animatable value within it. The OS has an animation thread that it uses as its frame timer, then at each tick it sends an update on the main thread to your animatable properties with their progressing values. (You can check the current state of these values on your presentationLayer.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With