何时在 Mac/iPhone 上使用 CALayer? [英] When to use CALayer on the Mac/iPhone?

查看:35
本文介绍了何时在 Mac/iPhone 上使用 CALayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑什么时候在 iPhone 或 Mac 上使用 CALayer,什么时候不使用它?CoreAnimation 在我基于 UIView 的对象上工作得很好,而无需使用 CALayer.什么时候深入学习这门课比较合适?

I'm slightly confused when to use CALayer on the iPhone or Mac and when not to use it? CoreAnimation works just fine on my UIView based objects without having to use CALayer. When is the appropriate time to dig into this class?

推荐答案

在我的基准测试中,UIView 和 CALayer 在 iPhone 上提供了大致相同的性能水平.正如 rpetrich 在他的评论中提到的,UIViews 是围绕 CALayer 的一个薄包装.在 Mac 上,CALayers 比 NSViews 轻得多.

In my benchmarks, UIView and CALayer provide about the same level of performance on the iPhone. As rpetrich mentions in his comment, UIViews are a thin wrapper around CALayers. On the Mac, CALayers are much more lightweight than NSViews.

正如 Ben 所指出的,您可以通过直接使用 CALayer 来超越隐式动画的功能,甚至可以通过 CATransform3D 提供一些 3D 效果.在许多情况下,您甚至可以通过访问支持层(如果视图是层支持的)来使用标准视图执行此操作.

As Ben points out, you can go beyond the capabilities of implicit animations by working directly with CALayers, even providing some 3-D effects through CATransform3D. In many cases, you can do this even with your standard views by accessing the backing layer (if the view is layer-backed).

另一个问题是跨平台(Mac/iPhone)代码.我的 iPhone 应用程序 主要视图使用全 CALayer 界面,因为我可以使用完全相同的界面用于在 Mac 对应界面中绘制该界面的代码.再举一个例子,我将引导您使用 Core Plot 框架,它可以绘制图形完全使用 CALayer 并且适用于 Mac 和 iPhone.CALayer 在两个平台上几乎相同,其中 UIView 和 NSView 具有非常不同的界面.

Another concern is cross-platform (Mac / iPhone) code. My iPhone application uses an all-CALayer interface for its primary view in large part because I can use the exact same code for drawing that interface in its Mac counterpart. For another example of this, I direct you to the Core Plot framework, which draws graphs entirely using CALayers and works on both Mac and iPhone. CALayers are pretty much the same on both platforms, where UIView and NSView have very different interfaces.

这篇关于何时在 Mac/iPhone 上使用 CALayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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