UINavigationController推送转换期间的低帧速率 [英] Low frame rate during UINavigationController push transition

查看:167
本文介绍了UINavigationController推送转换期间的低帧速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UINavigationController ,并从根视图控制器推送到下一个视图控制器。第二个视图控制器相当重,因为它有大量的初始化和子视图。

I have a UINavigationController, and push from the root view controller to the next view controller. This second view controller is fairly "heavy", in that it has a great deal of initialization and subviews.

我的问题是:过渡动画执行得非常糟糕。基本上,动画的帧速率非常低(我从推动画中得到的总帧数可能是3-4帧)。

My issue is this: the transition animation performs terribly. Basically, the animation suffers from a very low frame rate (I get maybe 3-4 frames in total out of the "push" animation).

我试过了各种不同的技术,包括两种不同的方法来手动设置过渡动画。在所有情况下,动画的前0.4-0.7秒都会受到这种不良帧率的影响。例如,如果我将过渡设置为5秒,那么前半秒左右的表现不佳,但动画的其余部分非常流畅。

I've tried a variety of different techniques, including two different methods to manually animate the transition. In all cases, the first 0.4-0.7 seconds of the animation suffers from this poor framerate. If I set the transition to take 5 seconds, for example, the first half second or so performs poorly, but the remainder of the animation is nice and smooth.

这导致我相信在转换开始时会发生某事 - 这会导致设备以非常低的帧速率进行动画制作。

This leads me to believe that "something" is happening at the beginning of the transition -- something which causes the device to animate at a very low framerate.

注入大量的 NSLog 语句进入我的代码,我看到发生了两件事。首先,显然第二个视图在推送过程中是延迟加载的。我通过在执行推送之前访问view属性上的getter来修复此问题。我可以确认这会导致在推动动画开始之前发生所有初始化。

After injecting a lot of NSLog statements into my code, I saw two things happen. First, obviously the second view is being lazy-loaded during the push. I fixed this by accessing the getter on the view property before executing the push. I can confirm that this results in all the initialization happening before the push animation begins.

其次,我的应用程序大部分时间在转换期间收到低内存警告。然而,即使在我没有得到内存警告的情况下,动画仍然表现得很差 - 让我相信这些都不是原因。

Second, my app most of the time receives a low memory warning during the transition. However, even in cases when I don't get the memory warning, the animation still performs just as poorly -- leading me to believe that neither of these things is the cause.

我的问题:是否有其他人在 UINavigationController 推送过渡动画中遇到了低帧率,但仅限于前0.4-0.7秒动画?是否有其他事情在幕后引发它,并且可以做任何事情吗?

My question: Has anyone else experienced a low framerate on a UINavigationController push transition animation, but only for the first 0.4-0.7 seconds of the animation? Is there something else going on behind the scenes that causes it, and can anything be done?

作为参考,这是我当前加载并推送到下一个视图的代码。我有意访问视图getter,以强制视图在转换之前加载和初始化(主要是为了排除问题)。此代码在主线程上使用 performSelectorOnMainThread ::: 执行,以响应Web服务回调。

For reference, here's my current code that loads and pushes to the next view. I'm purposefully accessing the view getter in order to force the view to load and initialize before the transition (mostly to rule out that as the issue). This code is executed on the main thread using performSelectorOnMainThread::: in response to a web service callback.

PlayingFieldViewController *v = [[PlayingFieldViewController alloc] initWithNibName:@"PlayingFieldView" bundle:[NSBundle mainBundle]];
UIView *lazy = v.view;
[appDelegate.navigationController pushViewController:v animated:YES];
[v release];

我还尝试了一些其他动画技术,结果相同:

I've also tried a few other animation techniques, all with the same result:

CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[appDelegate.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[appDelegate.navigationController pushViewController:v animated:NO];

和:

[UIView 
  transitionWithView:appDelegate.navigationController.view
  duration:1.0
  options:UIViewAnimationOptionTransitionCurlUp
  animations:^{
   [appDelegate.navigationController pushViewController:v animated:NO];
  }
  completion:NULL];


推荐答案

经过进一步测试,我能够诊断出问题。涉及的第二个视图包括许多 UIImageViews 。删除这些视图或隐藏它们可以解决问题。

After further testing, I was able to diagnose the problem. The second view involved includes many UIImageViews. Removing those views or hiding them fixes the problem.

让我失望的是,只有动画的第一部分遭受帧速率问题,而剩下的动画非常流畅(在动画较长的情况下)。这告诉我,即使所有子视图都存在,该设备也能够平滑地动画过渡动画。

What threw me off was the fact that only the first portion of the animation suffered from frame rate issues, while the remainder of the animation was perfectly smooth (in the case of longer animations). This shows me that the device is quite capable of animating the transition smoothly, even with all the subviews present.

我仍然不是iOS合成专家,但我猜测各个层正在布局和缓存,导致经济放缓。解决方法是在隐藏大部分子视图的情况下推送到视图,然后在视图可见时使用另一个动画显示它们。

I'm still not an expert on iOS compositing, but I'm guessing the various layers are being laid out and cached, leading to the slowdown. The workaround is to push to the view with most of the subviews hidden, then show them using another animation once the view is visible.

这篇关于UINavigationController推送转换期间的低帧速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆