美文网首页
UIView 和 CALayer 的关系

UIView 和 CALayer 的关系

作者: 公爵海恩庭斯 | 来源:发表于2016-12-13 14:02 被阅读50次

1. UIView 和 CALayer 的关系

Layers are not a replacement for your app’s views—that is, you cannot create a visual interface based solely on layer objects. Layers provide infrastructure for your views. Specifically, layers make it easier and more efficient to draw and animate the contents of views and maintain high frame rates while doing so. However, there are many things that layers do not do. Layers do not handle events, draw content, participate in the responder chain, or do many other things. For this reason, every app must still have one or more views to handle those kinds of interactions.
-- The Relationship Between Layers and Views

简单来说,UIView 是对 CALayer 的一个封装:

WWDC 2012 - Session 238 - iOS App Performance: Graphics and Animations

CALayer 负责绘制内容 contents。而 UIView 负责:1. 为 CALayer 提供内容 contents;2. 处理用户事件,参与响应链。

2. CALayer 如何绘制内容

A layer can display a filled background and a stroked border in addition to its image-based contents. The background color is rendered behind the layer’s contents image and the border is rendered on top of that image, as shown in Figure 2-3. If the layer contains sublayers, they also appear underneath the border. Because the background color sits behind your image, that color shines through any transparent portions of your image.

Adding a border and background to a layer
-- Layers Have Their Own Background and Border

3. UIImageView 如何使用 CALayer 绘制图片

既然直接对 CALayer 的 contents 属性赋值一个 CGImage 便能显示图片,所以 UIImageView 就顺利成章地诞生了。实际上 UIImage 就是对 CGImage(或者 CIImage) 的一个轻量封装。

WWDC 2012: iOS App Performance: Graphics and Animations
-- iOS App Performance: Graphics and Animations

参考

相关文章

  • 简述CALayer和UIView的关系

    简述CALayer和UIView的关系 答:UIView和CALayer是相互依赖的关系。UIView依赖与cal...

  • UIView和CALayer

    UIView和CALayer和有什么关系 UIview中有个属性layer,是CALayer类型。 CALayer...

  • CALayer和UIView详解

    关于UI的继承关系图: CALayer & UIView 区别 概念 CALayer和UIView的关系 可以说:...

  • iOS界面渲染流程

    前言:关系图 一、UIView 和 CALayer 的区别 ([详解CALayer 和 UIView的区别和联系]...

  • iOS中的UI事件传递&响应

    UIView和CALayer之间的关系和区别 关系 1.UIView中有个属性layer(CALayer类型)和b...

  • CALayer和UIView

    CALayer和UIView 1、为什么要提供UIView和CALayer两个平行的层级关系 1、UIVIew用于...

  • 2019-03-07

    UIView和CALayer关系 UIView继承自UI...

  • CALayer

    •CALayer和UIView的关系 –CALayer负责视图中显示内容和动画 –UIView负责监听和响应事件 ...

  • UI事件传递&响应

    UIView和CALayer之间的关系和区别UIView和CALayer UIView实际上里面有的属性,一个CA...

  • iOS相关题目-OC对象本质是一个结构体

    UIView和CALayer是啥关系?CALayer 是 QuartzCore 中的类 1. 首先UIView(继...

网友评论

      本文标题:UIView 和 CALayer 的关系

      本文链接:https://www.haomeiwen.com/subject/yibeettx.html