前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >UIView和CALayer

UIView和CALayer

作者头像
星宇大前端
发布2019-01-15 10:59:36
6450
发布2019-01-15 10:59:36
举报
文章被收录于专栏:大宇笔记大宇笔记

首先先看一下苹果对两个对象的描述

 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的工作结果和处理交互响应事件。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年03月01日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档