- 浏览: 762365 次
- 性别:
- 来自: 天堂
文章分类
最新评论
-
xiaozhao-521:
呀呀呀呀呀呀呀
RequestTest222 -
Andy_hyh:
打扰了,问下openmeeting源码可以运行起来吗?
Openmeetings安装 详细步骤 -
qindongliang1922:
擦,现在还行么,厉害
北京免费吃饭的地方 -
minixx77:
...
Openmeetings安装 详细步骤 -
wwwqqqiang:
喜欢楼主分享问题的方式,有思想
UIView 和 CALayer的那点事
UIView 和 CALayer的那点事
(1)老祖
万物归根,UIView和CALayer都是的老祖都是NSObjet。
1: UIView的继承结构为: UIResponder : NSObject。
可以看出UIView的直接父类为UIResponder 类, UIResponder 是gsm的呢?
官方的解释:
The UIResponder class defines an interface for objects that respond to and handle events. It is the superclass of UIApplication, UIView and its subclasses (which include UIWindow). Instances of these classes are sometimes referred to as responder objects or, simply, responders.
The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabel object draws a text string and a UIImageView object draws an image.
可见 UIResponder是用来响应事件的,也就是UIView可以响应用户事件。
2:CALayer的继承结构为: NSObject。
直接从 NSObject继承,因为缺少了UIResponder类,所以CALayer悲催的不能响应任何用户事件。
The CALayer class is the model class for layer-tree objects. It encapsulates the position, size, and transform of a layer, which defines its coordinate system. It also encapsulates the duration and pacing of a layer and its animations by adopting the CAMediaTiming protocol, which defines a layer’s time space.
从官方的解释可以看出,CALayer定义了position、size、transform、animations 等基本属性。那UIView的size、frame、position这些属性是从那里来的呢?上面的官方解释没有说明这一点,我们一会再分析
至此我们了解到了,UIView 和CALayer的基本信息和主要负责处理的事情。
(2)所属框架
1:UIView是在 /System/Library/Frameworks/UIKit.framework中定义的。
这个又是做什么的呢?
The UIKit framework provides the classes needed to construct and manage an application’s user interface for iOS. It provides an application object, event handling, drawing model, windows, views, and controls specifically designed for a touch screen interface.
可见UIKit主要是用来构建用户界面,并且是可以响应事件的(得意与UIView的父类UIResponder,至于UIResponderd的实现原理不是这次分析的目的,在此不做过多的解释)
在这里思考一个问题UIView既然是构建用户界面的,那他是通过什么方式绘制这些图片、文字之类的信息的呢?
Ios中的2D图像绘制都是通过QuartzCore.framework实现的。难道是通过QuartzCore.framework实现的?那又是通过什么方式和QuartzCore.framework联系起来的呢??我们一会再看。
2:CALayer是在/System/Library/Frameworks/QuartzCore.framework定义的。而且CALayer作为一个低级的,可以承载绘制内容的底层对象出现在该框架中。
现在比较一下uiview和calayer都可以显示图片文字等信息。难道apple提供了,两套绘图机制吗?不会。
UIView相比CALayer最大区别是UIView可以响应用户事件,而CALayer不可以。UIView侧重于对显示内容的管理,CALayer侧重于对内容的绘制。
大家都知道QuartzCore是IOS中提供图像绘制的基础库。并且CALayer是定义该框架中。难道UIView的底层实现是CALayer??
官方做出了明确的解释:
Displaying Layers in Views
Core Animation doesn't provide a means for actually displaying layers in a window, they must be hosted by a view. When paired with a view, the view must provide event-handling for the underlying layers, while the layers provide display of the content.
The view system in iOS is built directly on top of Core Animation layers. Every instance of UIView automatically creates an instance of a CALayer class and sets it as the value of the view’s layer property. You can add sublayers to the view’s layer as needed.
On Mac OS X you must configure an NSView instance in such a way that it can host a layer.
由此可见UIView是基于CALayer的高层封装。The view system in iOS is built directly on top of Core Animation layers.
UIView 的方法:
layerClass - Implement this method only if you want your view to use a different Core Animation layer for its backing store. For example, if you are using OpenGL ES to do your drawing, you would want to override this method and return the CAEAGLLayer class.
该方法保留了UIView的本质。即对UIView所管理的内容,任何显示也是受到CALayer的影响的。
- (3)相似支持
1:相似的树形结构
2:显示内容绘制方式
3: 布局约束
- (4) UIView 是什么,做什么
UIView是用来显示内容的,可以处理用户事件
- (5)CALayer是什么,做什么
CALayer是用来绘制内容的,对内容进行动画处理依赖与UIView来进行显示,不能处理用户事件。
- (6)为何有两套结构
并不是两套体系,UIView和CALayer是相互依赖的关系。UIView依赖与calayer提供的内容,CALayer依赖uivew提供的容器来显示绘制的内容。归根到底CALayer是这一切的基础,如果没有CALayer,UIView自身也不会存在,UIView是一个特殊的CALayer实现,添加了响应事件的能力。
- (7)两者之间的关系
发之于肤,血之于肉,灵之于魄,男人之于肾的关系。依存的关系
结论:
UIView来自CALayer,高于CALayer,是CALayer高层实现与封装。UIView的所有特性来源于CALayer支持。
评论
发表评论
-
iOS 自定义UIActionSheet
2012-12-18 16:07 16371一:模态视图 UIActi ... -
iOS Open Source : Popover API for iPhone
2012-01-20 15:02 1897http://iphonedevelopertips.com/ ... -
ios 任务、线程、定时器
2011-12-26 18:09 7971一:operations(任务) cocoa提供了三种 ... -
ios url缓存策略——NSURLCache、 NSURLRequest
2011-12-26 17:09 24306一:url 缓存策略 NSURLRequest ... -
ios NSInvocation简单使用
2011-12-22 16:39 6316在ios直接调用某个对象的消息是方法有两种: 一:perfo ... -
iphone 对Web Services的三种请求方式soap get post
2011-11-09 10:57 6365一:Using SO AP 1.1 POST / ... -
sdk3.2手势实例
2011-11-09 10:11 1701#import <UIKit/UIKit.h>@i ... -
关于iphone 利用hpple解析html的问题
2011-08-04 18:28 2166最近在用happe解析html中的图片。有个翻页操作,如果请 ... -
iphone hpple 解析html,xml
2011-07-19 16:21 2703使用Objective-C解析HTML或者XML,系统自带有两 ... -
激活 iPhone通过 GPRS 连接服务器功能的代码
2011-05-13 15:14 1605如果您的 iPhone 应用里含有连接服务器的功能,也许会遇到 ... -
address book api 图型
2011-04-28 15:51 1102最近要搞地址簿了,整理一下 -
[OmniGraffle]iPhone app原型制作工具
2011-04-06 17:35 3909在写程序之前,我们通常需要做一些mockup出来(不知道款爷有 ... -
自定义uislider 样式
2011-04-04 21:28 3788UIImage *stetchLeftTrack= [[UII ... -
iphone 下AsyncSocket网络库编程
2011-04-02 21:04 7584iphone的标准推荐CFNetwork ... -
进阶AlertView运用 - 登入设计
2011-04-01 17:52 2988说明:示范如何利用AlertView来制作系统登入的介面程式碼 ... -
iPad UIPopoverController弹出窗口的位置和坐标
2011-04-01 17:42 1954优化规则: TodoViewControlle ... -
iPhone系统自动化测试
2011-04-01 17:39 2569首先mac系统是必备的2 安装iPhone SD ... -
iphone上面编写具有root权限的程序
2011-04-01 17:31 6238正常途径下, 我们编写的程序发布在App store上, 使用 ... -
聊天。。。。。
2011-04-01 17:13 1048是得分手段 -
iOS开发基础:Modal View Controller的不同呈现方式
2011-04-01 16:40 2772ModalViewController可以有不同的呈现方式(m ...
相关推荐
为 iOS CALayer 添加 UIViewAutoresize 支持和快速 UIView 到 CALayer 的转换方法 安装 pod 'CALayer-AutoresizingMask' 用法 不要在这个storyboard或XIB使用自动布局,并使用您需要的自动调整大小蒙版。 热交换...
适用于iOS 9+的动画师,结合了现代UIView和CALayer动画API的最佳方面。 :party_popper: 隐式和显式加性动画。 :party_popper: 通过参数化运动。 :party_popper: 直接从手势识别器为动画提供速度。 :party_popper: ...
CardsAnimationDemo - swift, 《使用 UICollectionView 实现的一个卡片动画》不是直接操作所有 UIView 和 CALayer 的 transform3D 属性来实现整个效果的,而是使用 UICollectionView 来完成所有的视图管理和实现。
在开始之前呢,先了解一下UIView和CALayer大体的区别(重点列举了以下四点): •UIView 继承自 UIResponder,因此UIView 可以处理响应事件,而CALayer继承自NSObject,所以它只是负责内容的创建,绘制。 •UIView ...
UIView跟CALayer 单一原则 UIView为CALayer提供内容以及负责处理触摸事件,参与响应链 CALayer负责显示内容的Content 事件传递与视图响应链 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; - (BOOL...
一、UIView 与 CALayer 二、事件传递与视图响应链 : 三、图像显示原理 四、UI 卡顿掉帧原因 五、滑动优化方案 六、UI 绘制原理 七、离屏渲染
ParaMangar 将有序的UIView或CALayer动画渲染为您可以轻松用于 WatchKit 的动画。 这个项目深受启发,并试图通过多种方式对其进行改进,包括使API语法更像swift,添加动态UIImage生成等。 ParaMangar 在 MIT 许可下...
CALayer简介 1. CALayer是核心动画的基础,通过...2. 每个UIView内部都有一个CALayer类型的属性layer. 3. 在实现核心动画时,本质上是把CALayer中的内容 转换成位图,从而便于图形硬件的操作。 CALayer一些常用属性设置
其实UIView之所以能显示在屏幕上,完全是因为它内部的一个图层,在创建UIView对象时,UIView内部会自动创建一个图层(即CALayer对象),通过UIView的layer属性可以访问这个层 @property(nonatomic,readonly,retain) ...
目录一 iOS中的事件1 事件的产生和类型2 响应者对象3 UIview和CALayer二 事件传递和响应机制1 事件的传递2 系统实现3 视图的响应三 事件和runloop 一 iOS中的事件 1 事件的产生和类型 用户对iOS设备进行了一些操作, ...
带有UIImage,UIView和CALayer的文本附件 排除路径 自定义属性 自定义截断令牌 调试文本布局 文字选择 要求 iOS 9+ 安装 MPITextKit支持多种在项目中安装库的方法。 使用CocoaPods进行安装 pod 'MPITextKit' 使用...
CALayer_Swift是用Swift语言实现CALayer及其子类各种效果和变换的demo程序。 程序文件说明: ArrayDataSource.swift :分离出来的UITableViewDataSource,实现dataSource的封装和复用。 MainViewController.swift :主...
带有 UIImage、UIView 和 CALayer 的文本附件。 自定义突出显示文本范围以允许用户交互、文本解析器支持(内置降价/表情解析器)、文本容器路径和排除路径支持。 垂直表单布局支持(用于 CJK 文本)。 图像和属性...
脉冲层 向任何任意UIView添加可自定义的CALayer光晕效果。 完全用Swift编写。如何使用haloLayer = PulsingLayer ( pulseColor : UIColor ( white : 1.0 , alpha : 1.0 ))haloLayer. radius = 90.0haloLayer. ...
来自AsyncDisplayKit吗?...ASDisplayNode是UIView的抽象,UIView是CALayer的抽象。 与只能在主线程上使用的视图不同,节点是线程安全的:您可以在后台线程上并行实例化和配置它们的整个层次结构。 为了保持你的
UIView-IBInspectable 允许在界面生成器中更改 CALayer 属性的小型 Swift 扩展
* 在创建UIView对象时,UIView内部会自动创建一个层(即CALayer对象),通过UIView的layer属性可以访问这个层。当UIView需要显示到屏幕上时,会调用 drawRect:方法进行绘图,并且会将所有内容绘制在自己的层上,绘图...
简单易用的对象层次结构,可绘制到UIView或CALayer 高度可定制的。 要求 需要iOS 9或OS X 10.11 需要自动参考计数(ARC) 应用领域 ...还没有。 即将推出 制表符 动画制作 稳定性增强和错误修复 文献资料 记号语言...
首先要说的是CALayers 是屏幕上的一个具有可见内容的矩形区域,每个UIView都有一个根CALayer 其子类,如CAGradientLayer,CATextLayer, CAShapeLayer等等 2 、CAShapeLayer CAShapeLayer 是继承与clayer的一...
ASDisplayNode是UIView的抽象, UIView是CALayer的抽象。 与只能在主线程上使用的视图不同,节点是线程安全的:您可以在后台线程上并行实例化和配置它们的整个层次结构。 为保持其用户界面流畅和响应速度,您的...