简体   繁体   中英

Understanding ios UIView animation block and dispatch_async(dispatch_get_main_queue) block

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.)

The animation block you pass is called immediately . No need to use any queues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM