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

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

问题描述

我在使用CALayer在iPhone或Mac上和当不使用它时有点困惑? 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是CALayers的一个薄包装。在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指出,通过直接使用CALayers可以超越隐式动画的功能,甚至提供一些通过CATransform3D的3-D效应。在许多情况下,即使使用标准视图,也可以通过访问背景层(如果视图是基于layer的)来实现。

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对应。对于另一个示例,我引导您到核心图绘制框架,它绘制图表完全使用CALayers和工作在Mac和iPhone。 CALayers在两个平台上都是相同的,其中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天全站免登陆