I have an scroll view with some sophisticated animations happening during scrolling. Although after 2 weeks of finetuning the performance is acceptable now, the scrolling is not 100% smooth when the animations happen.
我有一个滚动视图,在滚动过程中会发生一些复杂的动画。尽管经过2周的微调后,现在可以接受性能,但是当动画发生时,滚动并不是100%平滑。
I know that core animation does animations in a background thread. But I wonder if it would help to split those animation blocks (10 of them at pretty much the same time) into threads.
我知道核心动画在后台线程中做动画。但我想知道是否有助于将这些动画块(其中10个在几乎同时)分割成线程。
There are a few methods that look interesting:
有几种方法看起来很有趣:
– performSelector:onThread:withObject:waitUntilDone: – performSelectorInBackground:withObject:
- performSelector:onThread:withObject:waitUntilDone: - performSelectorInBackground:withObject:
or is that nonsense to do?
或者是胡说八道?
2 个解决方案
#1
No, it won't help. As you correctly stated yourself, Core Animation already runs in a seperate thread. Core Animation is smart enough to handle animation blocks as efficiently as possible. I wouldn't advise interfering with it.
不,它没有用。正如你自己正确说明的那样,Core Animation已经在一个单独的线程中运行。核心动画足够智能,可以尽可能高效地处理动画块。我不建议干涉它。
The Core Animation Programming Guide says:
核心动画编程指南说:
An abstract animation interface that allows animations to run on a separate thread, independent of your application's run loop. Once an animation is configured and starts, Core Animation assumes full responsibility for running it at frame rate.
一个抽象动画界面,允许动画在单独的线程上运行,与应用程序的运行循环无关。配置并启动动画后,Core Animation将承担以帧速率运行动画的全部责任。
#2
Are you sure the choppy behavior is really from CA? Do you have anything else going on?
你确定波涛汹涌的行为真的来自CA吗?你还有别的事吗?
If you have any background network access, consider moving that into a separate thread - the time taken to service those calls takes away from time the UI spends updating the screen as you scroll.
如果您有任何后台网络访问权限,请考虑将其移动到一个单独的线程中 - 维护这些调用所花费的时间会消耗UI在滚动时更新屏幕所花费的时间。
#1
No, it won't help. As you correctly stated yourself, Core Animation already runs in a seperate thread. Core Animation is smart enough to handle animation blocks as efficiently as possible. I wouldn't advise interfering with it.
不,它没有用。正如你自己正确说明的那样,Core Animation已经在一个单独的线程中运行。核心动画足够智能,可以尽可能高效地处理动画块。我不建议干涉它。
The Core Animation Programming Guide says:
核心动画编程指南说:
An abstract animation interface that allows animations to run on a separate thread, independent of your application's run loop. Once an animation is configured and starts, Core Animation assumes full responsibility for running it at frame rate.
一个抽象动画界面,允许动画在单独的线程上运行,与应用程序的运行循环无关。配置并启动动画后,Core Animation将承担以帧速率运行动画的全部责任。
#2
Are you sure the choppy behavior is really from CA? Do you have anything else going on?
你确定波涛汹涌的行为真的来自CA吗?你还有别的事吗?
If you have any background network access, consider moving that into a separate thread - the time taken to service those calls takes away from time the UI spends updating the screen as you scroll.
如果您有任何后台网络访问权限,请考虑将其移动到一个单独的线程中 - 维护这些调用所花费的时间会消耗UI在滚动时更新屏幕所花费的时间。