首先先看一下苹果对两个对象的描述
UIView:http://blog.csdn.net/ZY_FlyWay/article/details/58611627
CALayer:http://blog.csdn.net/ZY_FlyWay/article/details/59039800
我们从苹果官方文档可以知道:
UIView 继承于 UIResponder (UIResponder继承于NSObject)
CALayer继承于 NSObject
所以他们之间的差异来自于UIResponder定义的那一部分。
1、UIResponder是干嘛的呢?
答:看完这一个就懂了 一句话UIVIew可以响应事件,而Layer不可以。
2、UIView和CALayer有什么关系呢。
答:If the layer object was created by a view, the view typically assigns itself as the layer’s delegate automatically, and you should not change that relationship. For layers you create yourself, you can assign a delegate
object and use that object to provide the contents of the layer dynamically and perform other tasks. A layer may also have a layout manager object (assigned to the layoutManager
property) to manage the layout of subviews separately.
从官方文档可以了解到:UIView初始化的时候会自动创建Layer,而layer会自动指定代理是view。所以他俩是代理和被代理的关系。
3、那么layer在view中有什么用呢?
view中对于图片的渲染,和一些动画操作都是layer完成的,view只是呈现layer的工作结果和处理交互响应事件。