简体   繁体   English

调用UIView animateWithDuration后,关键帧动画需要很长时间才能开始

[英]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. 每当我出现并关闭视图控制器(称为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 当我加载第二个视图控制器View Controller 2时,在mainWindow顶部显示插页式加载视图,其中mainWindow是

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. 我遇到的问题是,如果我多次加载View Controller 1(例如5次以上),然后加载View Controller 2,则微调器动画开始花费很长时间才能开始。 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. 再次进入View Controller 1后,再进入View Controller 2,View Controller 2的动画开始需要很长时间,以至于在旋转器有机会开始动画之前就删除了加载视图。

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? 我离开View Controller 1时,是否没有正确删除UIView动画与它有关?

Call the method in the main_queue , this solved my problem. 调用main_queue中的方法,这解决了我的问题。

dispatch_async(dispatch_get_main_queue(), ^{

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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