屏幕保护程序中的动画(核心)生涩/紧张?
我为 Leopard 构建了一个使用核心动画的屏幕保护程序。 它不会做任何过于复杂的事情; 使用 CALayers 和 CATextLayers 树来生成以下结构的数据“表”:
- root
› maincontainer
› subcontainer
› row [multiple]
› cell [multiple]
› text layer
屏幕上同时最多渲染 50 个 CALayers。
构建“表”后,我将使用 CABasicAnimation 将“子容器”动画添加到视图中。 再说一次,我没有做任何花哨的事情——只是简单的淡入。
问题是,虽然动画确实发生了,但观看起来却痛苦。 在我的开发机器(3.06Ghz iMac,4GB RAM)上它很不稳定,并且似乎将动画分成 10 个步骤,而不是显示逐渐的变化。
在屏幕保护程序的目标 ppc mac-mini 上,情况会变得更糟; 它甚至拒绝播放动画,通常从动画的开始(0%不透明度)到中间(50%)然后完成“补间”。
我对 ObjectiveC 比较陌生,我的经验是基于使用垃圾收集环境,但我不敢相信在屏幕保护程序开始导致此类问题时我泄漏了足够的内存。
另外,我很确定这不是硬件问题。 我测试了使用核心动画的内置屏幕保护程序,并下载了一些基于 CA 的免费屏幕保护程序进行比较,它们在两台计算机上运行都没有问题。
Google 上关于在屏幕保护程序中使用 CA 或一般使用 CA 的信息相当薄弱,并且关于分析/麻烦屏幕保护程序的建议/教程似乎不存在。 因此,社区可以提供的任何帮助都将受到欢迎!
--- 更新 ---
似乎隐式动画有助于使事情变得更加顺利。 仍然有点不稳定,但不像我的解决方案中那样尝试使用显式动画为所有内容设置动画那么糟糕。
I've built a screensaver for Leopard which utilises core-animation. It doesn't do anything overly complicated; uses a tree of CALayers and CATextLayers to produce a "table" of data in the following structure:
- root
› maincontainer
› subcontainer
› row [multiple]
› cell [multiple]
› text layer
At most there are 50 CALayers rendered on the screen at any one time.
Once I've built the "table", I'm adding animating the "subcontainer" into view using CABasicAnimation. Again, I'm not doing anything fancy - just a simple fade-in.
The problem is that while the animation does happen its painful to watch. It's jerky on my development machine which is a 3.06Ghz iMac with 4GB of RAM, and seems to chop the animation into 10 steps rather than showing a gradual change.
It gets worse on the ppc mac-mini the screensaver is targeted for; it refuses to even play the animation, generally "tweening" from the beginning of the animation (0% opacity) to half-way (50%) then completing.
I'm relatively new to ObjectiveC and my experience is based on using garbage-collected environments, but I can't believe I'm leaking enough memory at the point the screensaver starts to cause such problems.
Also, I'm quite sure its not a problem with the hardware. I've tested the built-in screensavers which use core-animation, and downloaded a few free CA-based for comparison, and they run without issue on both machines.
Information is pretty thin on Google with regards to using CA in screensavers, or using CA in general for that matter, and advice/tutorials on profiling/troubling screensavers seems to be non-existant. So any help the community can provide would be well welcomed!
--- UPDATE ---
Seems as though implicit animations help smooth things out a little. Still kinda jerky, but not as bad as trying to animate everything with explicit animations as in my solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
屏幕保护程序没有什么特别之处。 我假设您已经开始阅读核心动画编程指南? 通过 Instruments 运行它会给你很多关于你在哪里花费了太多时间的信息。
您用于淡入的代码将会很有用。 对于您所描述的内容,您甚至不需要 CABasicAnimation; 您只需设置图层的可动画属性,它们默认会动画。 确保您已阅读 隐式动画。 该页面的其余部分可能也有用。
你在 CoreAnimation 中的大部分工作都是让路。 我通常知道它在做什么,大多数问题都来自于事后猜测或试图告诉它太多。
There isn't much special about a screen saver. I assume you've started with the Core Animation Programming Guide? Running it through Instruments will give you a lot of information about where you're taking too much time.
The code you're using to do the fade-in would be useful. For what you're describing, you don't even need CABasicAnimation; you can just set the animatable properties of the layers, and they by default animate. Make sure you've read up on Implicit Animations. The rest of that page is probably of use as well.
Most of your job in CoreAnimation is getting out of the way. I generally knows what it's doing, and most problems come from second guessing it to trying to tell it too much.