简体   繁体   中英

Keyframe animation takes long time to start after UIView animateWithDuration is called

I am using the following method to chain animations:

[UIView animateWithDuration:0.3 delay:0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^(){
                     // Animations here
                 }
                 completion:^(BOOL finished) {
                     if (finished) {
                         // Chained animation
                     }
                 }];

These animations play whenever I present and dismiss a view controller, call it View Controller 1.

When I load a second view controller, View Controller 2, I display an interstitial loading view on top of mainWindow, where mainWindow is

UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];

This interstitial loading view shows a spinner that is animated using a keyframe animation.

The problem I am running into is that if I load View Controller 1 multiple times (say 5+ times), then load View Controller 2, the spinner animation begins to take a long time to start. After entering View Controller 1 several more times, then entering View Controller 2, View Controller 2's animation takes so long to begin that the loading view is removed before the spinner ever gets a chance to start animating.

Does anyone know what might be causing this behavior? Does it have anything to do with UIView animations not being properly removed when I leave View Controller 1?

Call the method in the main_queue , this solved my problem.

dispatch_async(dispatch_get_main_queue(), ^{

    [UIView animateWithDuration:0.3 delay:0
                options:UIViewAnimationOptionCurveEaseOut
             animations:^(){
                 // Animations here
             }
             completion:^(BOOL finished) {
                 if (finished) {
                     // Chained animation
                 }
             }];
});

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