CALayer 与 UIView

1、关系

On iOS, every UIView is backed by a Core Animation CALayer. Simply speaking,UIView inherit from NSResponder,handle events from users, contains CALayer,which inherit from NSObject,mainly focus on rendering,animation etc.

One thing UIViews provide over CALayers is built-in support for user interaction. They handle hit-testing on touches and other related actions that you would need to build yourself if managing a hierarchy of CALayers. It‘s not that hard to implement this yourself, but it is extra code you‘d need to write when building a CALayer-only interface.

You will often need to access the underlying layers for a UIView when performing more complex animations than the base UIView class allows. UIView‘s animation capabilities have grown as the iOS SDK has matured, but there are still a few things that are best done by interacting with the underlying CALayer.

2、功能

UIView 主要是对显示内容的管理,CALayer 主要侧重显示内容的绘制。

3、动画 (可参考 objc.io - 动画 部分)

在对UIView 的属性修改时不会产生默认动画,而对单个 layer 属性直接修改会产生默认动画。因为UIView 默认情况下禁止了 layer 动画,但是在 animation block 中又重新启用了它们。

4、CALayer

The neat thing about the CALayer class is that it contains a lot of properties that you can set on it to affect the visual appearance, such as:

  • The size and position of the layer
  • The layer’s background color
  • The contents of the layer (an image, or something drawn with Core Graphics)
  • Whether the corners of the layers should be rounded
  • Settings for applying a drop shadow to the layer
  • Applying a stroke around the edges of the layer
  • And much more!

The other neat thing about the properties on CALayer is that most of them are animatable.

参考资料:

时间: 2024-08-02 10:58:15

CALayer 与 UIView的相关文章

CALayer与UIView

CALayer的基本属性 CALayer和UIView的关系 position和anchorPoint的作用 1.CALayer的基本属性 UIView之所以能显示在屏幕上,完全是因为它内部的一个图层(CALayer对象),UIView对象创建时,内部会自动创建一个图层与之相关联,通过UIView的layer属性可以访问这个层 @property(nonatomic,readonly,retain)CALayer*layer; 当UIView需要显示到屏幕上时,会调用drawRect:方法进行绘

CALayer与UIView的区别

这篇文章主要表达的是这两个类的区别和少量的联系. 1.首先要明确的一点就是CALayer继承自NSObject,而UIView集成自NSResponder.所以UIView是可以相应用户的点击事件的,而CALayer更多的是做渲染和动画效果. 2.第二个就是CALayer和UIView都可以在屏幕上展示.有什么区别吗?当然了!每个在页面上展示的UIView都是要在自己的根layer上进行对自己的绘制的!就好比layer是画板,而view是画笔. 3.第三个就是它们两个在展示效率上并没有很大的差别

CALayer与UIView的关系

CALayer属于Core Animation部分的内容,比较重要而不太好理解.以下是园子中看到的一篇文章的摘录: 1. UIView是iOS系统中界面元素的基础,所有的界面元素都是继承自它.它本身完全是由CoreAnimation来实现的.它真正的绘图部分,是由一个CALayer类来管理.UIView本身更像是一个CALayer的管理器,访问它的跟绘图和跟坐标有关的属性,例如frame,bounds等,实际上内部都是在访问它所包含的CALayer的相关属性. 2. UIView有个重要属性la

详解CALayer 和 UIView的区别和联系

详解CALayer 和 UIView的区别和联系 1.首先UIView可以响应事件,Layer不可以. UIKit使用UIResponder作为响应对象,来响应系统传递过来的事件并进行处理.UIApplication. UIViewController.UIView.和所有从UIView派生出来的UIKit类(包括UIWindow)都直接或间接地继承自 UIResponder类. 在 UIResponder中定义了处理各种事件和事件传递的接口, 而 CALayer直接继承 NSObject,并没

IOS开发-CALayer和UIView详细汇总

1.    CALayer和UIView之间的关系: 在iOS系统中,你能看得见摸得着的东西基本上都是UIView,比如UI控件.图标等等,都是UIView. 其实UIView之所以能显示在屏幕上,完全是因为它内部的一个层(CALayer). 在创建UIView对象时,UIView内部会自动创建一个层(即CALayer对象),通过UIView的layer属性可以访问这个层.当UIView需要显示到屏幕上时,会调用drawRect:方法进行绘图,并且会将所有内容绘制在自己的层上,绘图完毕后,系统会

CALayer和UIView

前言 本次分享将从以下方面进行展开: 曾被面试官问倒过的问题:层与视图的关系 CALayer类介绍及层与视图的关系 CAShapeLayer类介绍 UIBezierPath贝塞尔曲线讲解 CoreAnimation之动画子类介绍 CATransitionAnimation类实现各种过滤动画 关于Core Animation在iOS系统中的关系图如下: 可以看出,Core Animation是相对上层的封装,介于UIKit与Core Graphics.OpenGL/OpenGL ES之间.最底下还

CALayer和UIView的区别

转载:http://www.cnblogs.com/Twisted-Fate/p/4773544.html 1.UIKit使用UIResponder作为响应对象,来响应系统传递过来的事 件并进行处理.UIApplication.UIViewController.UIView.和所有从UIView派生出来的UIKit类(包括 UIWindow)都直接或间接地继承自UIResponder类. 在 UIResponder中定义了处理各种事件和事件传递的接口, 而 CALayer直接继承 NSObjec

UIView与CALayer的区别

今天和大家分享一下CALayer和UIView的区别: 1.UIKit使用UIResponder作为响应对象,来响应系统传递过来的事件并进行处理.UIApplication.UIViewController.UIView.和所有从UIView派生出来的UIKit类(包括UIWindow)都直接或间接地继承自UIResponder类. 在 UIResponder中定义了处理各种事件和事件传递的接口, 而 CALayer直接继承 NSObject,并没有相应的处理事件的接口,两者最明显的区别是 Vi

UIView CALayer 的区别

UIView与CALayer的区别,很详细 研究Core Animation已经有段时间了,关于Core Animation,网上没什么好的介绍.苹果网站上有篇专门的总结性介绍,但是似乎原理性的东西不多,看得人云山雾罩,感觉,写那篇东西的人,其实是假设读的人了解界面动画技术的原理的.今天有点别的事情要使用Linux,忘掉了ssh的密码,没办法重新设ssh,结果怎么也想不起来怎么设ssh远程登陆了,没办法又到网上查了一遍,太浪费时间了,痛感忘记记笔记是多么可怕的事情.鉴于Core Animatio