ios layer的学习

iOS 逆向学习 - iOS Architecture Core OS Layer Core OS Layer 是 iOS 系统的最低层,直接与硬件交互,提供系统资源管理、设备驱动、文件系统、安全框架等底层服务。它是整个 iOS 操作系统架构的基础,其稳定性和性能直接影响系统的整体表现。该层的组件包括Kernel(XNU 内核)Device Drivers(设备驱动)File System(文件系统)和Security Frameworks(安全框架)。XNU 内核是核心模块,整合了 Mach 和 BSD 的功能。提供硬件抽象接口,支持动态加载驱动。确保系统和数据的安全性。 阅读详情
layer类似于ps的图层,如果把一个uiview看做图片的画,layer就像是图层.一个图片是由很多个大小不同的有层次的图层构成的,uiview也是.

1. 一个view有一个underlying layer,它是这个view所有的draw的实现者,可通过view的layer property获得,但是它没有相应的view property,相反的,view是这个layer的delegate.

如果想改变view的underlying layer, 需实现view的 +(class) layerClass{}函数,返回自定义的layer类.往往这个类不负责具体的画图,只是负责组织多个子layer的显示.

view和layer的关系:view通过layer画图,layer缓存了所有的绘图;如此,layer可以被用来操作改变view的外观,而不用每次都需要view去绘制自己.这就是contentstretchmode的机理,当view的bounds改变时,ios的绘图系统只是简单的拉伸和重新排列缓存的layer图像.

2.layer的层级
layer的层级和view相似,一个layer有多个sublayer,一个sublayer只有一个最近的superlayer.

有一些列的函数控制layer的层级顺序,同view想似:addsublayer;insertsublayer:atindex(below/above);
replacesublayer:with; removefromsuperlayer.

同uiview的subviews property不同,layer的sublayers是可写的.因此可以一次性改变layer的多个sublayers;如果要移除所有的,只需置nil即可.

layer同时也有zposotion的属性,拥有低的zposition的layer比高的先绘制.当有时使用sublayer不便控制层级时,使用zpositon是个很好的选择.

3.layer的位置
控制layer的位置使用两个property.
position 一个superlayer坐标系下的坐标;
anchorpoint 一个本身坐标系下的坐标;
如同属性名称一样,就像用图钉在墙上订一个图片,position表示的是图钉在墙上坐标,anchorpoint表示是图钉在图片上坐标.

4.CAScrollLayer
使用cascrolllayer可以实现:通过改变一个layer的origin坐标,显示它的一部分内容.它的maskstobounds属性一般设为yes,这样就只能看见它的bounds内的内容.
可以通过调用cascrolllayer本身的函数或者调用它的sublayer函数实现layer的滚动功能
Talking to the superlayer (the CAScrollLayer)
scrollToPoint: changes the CAScrollLayer’s bounds origin to that point. scrollTo- Rect: changes the CAScrollLayer’s bounds origin minimally so that the given por- tion of the bounds rect is visible.
Talking to a sublayer
scrollPoint: changes the CAScrollLayer’s bounds origin so that the given point of the sublayer is at the top left of the CAScrollLayer. scrollRectToVisible: changes the CAScrollLayer’s bounds origin so that the given rect of the sublayer’s bounds is within the CAScrollLayer’s bounds area. You can also ask the sublayer for its visibleRect, the part of this sublayer now within the CAScrollLayer’s bounds.

5.layout
当一个layer的bounds发生改变或者显式调用了setNeedsLayout,它的layoutsublayers函数被调用,因此需要重写该函数实现layout.同时也可以在delegate中重写layoutsublayersoflayer,比如在uiview中为实现其underlying layer的layout,实现该函数.

layout的key-value codeing:

6.drawing in a layer

layer有一个content property,类似于uiimageview的image.但是它的类型是cgimageref.

同uiview的drawrect:类似,可以通过实现如下四个函数来提供layer的content或者重绘layer.

display in a subclass
Your CALayer subclass can override display. There’s no graphics context at this point, so display is pretty much limited to setting the contents.

drawInContext: in a subclass
Your CALayer subclass can override drawInContext:. The parameter is a graphics context into which you can draw directly; the discussion of drawing from Chap- ter 15 thus pertains.

displayLayer: or drawLayer:inContext: in the delegate
You can set the CALayer’s delegate property, and implement displayLayer: or drawLayer:inContext:. They are parallel to display and drawInContext:, the former providing no graphics context so that it’s fit mostly for setting the contents, and the latter providing a graphics context into which you can draw directly.

不能改变underlying layer的delegate.
尽量不要让layer重新绘制自己,除非你自己想要这么做

当一个uiview调用了setneessdisplay,他的underlying layer被也被发送了setneedsdisplay函数,除非该view没有任何drawrect的实现(这种情况下,默认view不需要重绘).因此如果需要view重绘时underlying layer同时重绘,至少需要实现一个空的drawrect:.

7. layer的contents resizing and positioning
一旦layer有了contents,不管是通过设置content还是通过draw获得的,都有如下属性:

contentsGravity:类似于uiview的contentsmode,是拉伸满整个view的bounds,还是在view上居中显示.

contentsRect:用于表述将要绘制的contents image的部分内容.使用这个属性,可以很方便的绘制一个大图的一部分,而不需要重绘或者改变contents image.同样可以使用contents rect缩小contents image,只需要把contents rect设置的比contents大,为了防止边缘效应,需要给contengs image一个清晰的像素边框

contentsCenter:用于描述当contentsgravity被设置成拉伸状态时,拉伸的中心.

needsdisplayonboundschan ge:yes说明bounds发生改变时重绘,无关contentsgravity;NO说明bounds发生改变时不重绘,只是利用cache的image采用contentgravity以及参考contentscenter拉伸.


8.系统的一些拥有自己绘制功能的layer.

CATextLayer:
catextlayer拥有string property,可以是NSString或NSAttributedString,以及其他的format的property,然后她负责绘制string.text和contents的是冲突的,因此一般不对catextlayer设置contents.
catextlayer可以实现uilabel不能实现的功能;以为使用了nsattributedstring,可以显示不同大小,字体,下划线等的文字.

CAShapeLayer
它有一个path的property,CGPath,可以填充或者画出,或者同时填充和画出响应的path.

CAGradientLayer
将背景简单的填上一个线性的放射图样.

9.Transform

CATransform3D:该transform发生在anchorPoint处延伸的三维空间中.
对于应用在catransform3d上的角度变化,需要提供一个坐标描述角度变化发生时,参考的向量.顺时针是从逆着参考方向向量的方向看过去的.

为了做出透视变换,需要将layer的正交投射和其superlayer的投射变换结合起来,才能做出实际的透视效果。

However, there’s a widely used trick for introducing a quality of perspective into the way layers are drawn: make them sublayers of a layer whose sublayerTransform prop- erty maps all points onto a “distant” plane. (This is probably just about the only thing thesublayerTransform property is ever used for.) Combined with orthographic projec- tion, the effect is to apply one-point perspective to the drawing, so that things do get perceptibly smaller in the negative z-direction.

ios <wbr>layer的一些学习

g.anchorPoint = CGPointMake(1,0.5);
g.position = CGPointMake(CGRectGetMaxX(self.bounds), CGRectGetMidY(self.bounds)); g.transform = CATransform3DMakeRotation(M_PI/4.0, 0, 1, 0);
CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0/1000.0;
self.sublayerTransform = transform;

10. CATransformLayer
这个layer本身不实现任何绘制,它仅仅是为了实现有层次的layer的一个载体。它的sublayers本身就有一个depth的概念。详情见p351.

11. Transforms and Key-Value Coding

使用transform时,可以使用key-value的模式

g.transform = CATransform3DMakeRotation(M_PI/4.0, 0, 1, 0);

等价于

[g setValue:[NSNumber numberWithFloat:M_PI/4.0] forKeyPath:@"transform.rotation.y"];

可以使用的transform keyvalue coding 有:

rotation.x, rotation.y, rotation.z, rotation (same as rotation.z), scale.x, scale.y, scale.z, translation.x, translation.y, translation.z, and translation


12. layer的其他属性:

shadow

A layer can have a shadow, defined by its shadowColor, shadowOpacity, shadowRadius, and shadowOffset properties. To make the layer draw a shadow, set the shadow- Opacity to a nonzero value. The shadow is normally based on the shape of the layer’s nontransparent region, but deriving this shape can be calculation-intensive (so much so that in early versions of iOS, layer shadows weren’t implemented). You can vastly improve performance by defining the shape yourself and assigning this shape as a CGPath to theshadowPath property.

border and corner

A layer can have a border (borderWidth, borderColor); the borderWidth is drawn inward from the bounds, potentially covering some of the content unless you compensate.

A layer can be bounded by a rounded rectangle, by giving it a cornerRadius greater than zero. If the layer has a backgroundColor, that background is clipped to the shape of the rounded rectangle. If the layer has a border, the border has rounded corners too.

光栅化rasterize

If a layer is complex (perhaps with shadow, sublayers, and so forth) and if this seems to be a performance drain (especially when scrolling or animating the layer), you may be able to gain some efficiency by “freezing” the entirety of the layer’s drawing as a bitmap. In effect, you’re drawing everything in the layer to a secondary cache and using the cache to draw to the screen. To do this, set the layer’s shouldRasterize to YES and its rasterizationScale to some sensible value (probably [UIScreen main- Screen].scale). You can always turn rasterization off again by setting should- Rasterize to NO, so it’s easy to rasterize just before some massive or sluggish rear- rangement of the screen and then unrasterize afterward. (In addition, you can get some cool “out of focus” effects by setting the rasterizationScale to around 0.3.)

13.layer的key-value coding(KVC)
layer没有tag属性,但是它与kvc属性兼容,因此可以实现它的  defaultValueForKey:  class method 静态方法,返回一个自定义的key值,需要时返回即可。setkey:forvalue    valueforkey可以实现不使用成员变量和tag的方法。
IC618新手避坑指南:从零在Linux上配置Cadence Virtuoso环境(含cds.lib文件详解) 本文详细介绍了在Linux系统上配置Cadence Virtuoso IC618环境的完整指南,特别针对新手常见问题提供解决方案。重点解析了cds.lib文件的关键配置,包括库路径定义和工艺库管理,并分享了高效工作流设置和典型问题排查技巧,帮助工程师快速搭建稳定的EDA设计环境。 阅读详情

相关推荐

双相机坐标系标定

工业双相机对位标定

sinat_33762356的博客 8317

关于Layer的一些认识

layer类似于ps的图层,如果把一个uiview看做图片的画,layer就像是图层.一个图片是由很多个大小不同的有层次的图层构成的,uiview也是. 1. 一个view有一个underlying layer,它是这个view所有的draw的实现者,可通过view的layer property获得,但是它没有相应的view property,相反的,view是这个layer的delegat

dean19900504的专栏 7195

Fat-Tree Topo Architecture(胖树拓扑结构)

背景 最近在搜索关于Fat-Tree的相关资料时,发现网上内容比较少,很多博客是相互转载的,拓扑结构图也加载不出来,使得对Fat-Tree的理解过于抽象。 实践 传统数据中心采用多层级的树形结构,这种结构针对客户端/服务器(C/S)模式能有较好的效果。树形结构包括单根树和多根树。多根数的根节点往往作为备份节点存在(我们以方格代表交换机)。 传统单根/多根拓扑结构有以下缺点:成本高,根部交换机必须要有足够大的带宽来满足下层服务器之间的通信;性能瓶颈,无法满足数据中心内部大规模的MapReduce和数据拷贝。

金色牛神的专栏 3万+

IOS进阶 - CALayer简单介绍

第一部分:简介 一、什么是CALayer      * 在iOS系统中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮、一个文本标签、一个文本输入框、一个图标等等,这些都是UIView。      * 其实UIView之所以能显示在屏幕上,完全是因为它内部的一个层。      * 在创建UIView对象时,UIView内部会自动创建一个层(即CALayer对象),通过UIV

LXL_815520的博客 3031

避坑指南:将大华官方Java SDK无缝迁移到SpringBoot 2.x项目的完整流程

本文详细介绍了如何将大华官方Java SDK无缝迁移到SpringBoot 2.x项目,重点解决内存管理、连接池设计和异步处理等核心问题。通过设备连接池化、异步非阻塞接口改造和内存管理优化,实现刷卡、刷脸等认证功能的高效整合,提升Web服务的稳定性和性能。

weixin_42557830的博客 416

Mellanox CX7网卡搭配400G光模块实战:从选型到部署的完整指南

本文详细解析了Mellanox CX7网卡与400G光模块的选型策略与部署实践,涵盖硬件对比、兼容性验证及性能调优。重点介绍了OSFP光模块的选择要点和常见问题排查方法,帮助用户构建高性能网络基础设施,适用于AI训练、金融交易等场景。

efc1234567的博客 1289

PCB Layout各层含义与分层原则

内容包括PCB绘图软件各层含义的详细介绍以及一些在实际工程中的应用,Layout时多层板分层原则与阻抗匹配,Gerber文件的含义等。

让你爱上电路设计 2万+

智能车轮腿组‘定点排雷’科目全解析:从雷区识别到姿态控制

本文深入解析了智能车竞赛轮腿穿越组‘定点排雷’科目的核心技术。从构建鲁棒的视觉识别系统,到融合编码器与IMU进行厘米级定位,再到实现框内高精度旋转的姿态控制,提供了一套完整的从感知到执行的闭环技术方案,助力参赛队伍攻克这一高难度科目。

weixin_29161719的博客 639

关于layerX,layerY

当需要取到鼠标点击相对于层的位置信息时,在ie下可以用event.offsetX, evnet.offsetY,在Firefox下是event.layerX, event.layerY。但是firefox下总是有问题,取到的不是相对于层的坐标,而是pageX,pageY。 Google了半天也没有发现什么解决办法,最后在一个网站看到一个例子,原来在层中要设置position为absolute或者r

qq807700656的专栏 1340

Unity Tilemap瓦片动态缩放:保持网格尺寸不变的三种实现方案

本文详细探讨了在Unity中实现Tilemap瓦片动态缩放同时保持网格尺寸不变的三种核心方案。针对编辑器静态调整、整体风格化处理及运行时动态控制等不同场景,分别解析了直接修改瓦片属性、调整Tilemap Renderer材质参数以及使用SetTransformMatrix与Matrix4x4矩阵变换的实践方法、优缺点及选型指南,为2D游戏开发提供灵活高效的视觉与交互解决方案。

grass的博客 626

电力现货市场出清机制与节点电价计算实战解析

本文深入解析了电力现货市场的出清机制,特别是节点边际电价的计算原理与实战应用。通过一个基于Matlab和IEEE30节点系统的完整案例,详细演示了如何利用最优潮流模型求解市场出清价格,并提取节点电价,揭示了电网阻塞如何影响实时电价的形成。

weixin_29061425的博客 949

【IC】芯片金属层(Metal Layer)

芯片的金属层(Metal Layer)是指集成电路芯片内部用于信号传输和电源分配的导电层。这些金属层通常是由铝、铜或其他导电材料制成,通过在芯片的不同部分之间布线,实现电路功能。

qq_38801607的博客 1万+

地统计插值学习心得(一)

(创建地统计图层工具用于根据现有的地统计图层或者地统计模型来创建包含新要素数据集的地统计图层,也就是使用构建好的地统计模型用到新的数据集中)这表明,远离极值的区域预测不受极值的影响,并且还表明,包括极值会导致钼元素浓度高的区域周围的预测明显变高。通常,我们使用同一个数据集进行建模和预测,但是在实际插值过程中,这两步的数据可以是不同的,这就是处理极值的诀窍。如果你的数据集有无法忽略的极值时(比如这些钼元素浓度),一种常见的方法是首先显式移除极值进行建模,然后在预测中使用整个数据集(包括极值)。

JData_Engineer的博客 286

ios layer的一些学习

layer类似于ps的图层,如果把一个uiview看做图片的画,layer就像是图层.一个图片是由很多个大小不同的有层次的图层构成的,uiview也是. 1. 一个view有一个underlying layer,它是这个view所有的draw的实现者,可通过view的layer property获得,但是它没有相应的view property,相反的,view是这个layer的delegat

huifeidexin_1的专栏 2692

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

iOS 逆向学习 - iOS Architecture Cocoa Touch Layer

Cocoa Touch Layer 是 iOS 应用程序的核心开发层,涵盖了用户界面、事件处理、通知、多任务等关键功能。对于逆向开发来说,掌握 Cocoa Touch Layer 的原理和框架结构,可以帮助深入了解目标应用的行为和功能逻辑,同时为修改界面、分析事件流和 Hook 系统调用奠定基础。作为 iOS 应用开发的核心,Cocoa Touch Layer 封装了许多便捷的工具和 API,使开发者能够快速创建直观、高性能的应用程序。的架构和工作原理,是分析应用功能、界面交互及事件流的基础。

qq_45797625的博客 2306

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

iOS学习——核心动画之Layer基础

iOS学习——核心动画之Layer基础 1、CALayer是什么? CALayer我们又称它叫做层。在每个UIView内部都有一个layer这样一个属性,UIView之所以能够显示,就是因为它里面有这个layer才具有显示的功能。我们可以通过操作CALayer对象,可以很方便地调整UIView的一些外观属性,可以给UIView设置阴影,圆角,边框等等... 2、如何操作layer改变UIView外观?   2.1设置阴影 //默认图层是有阴影的, 只不过,是透明的 _RedView...

imherer的博客 443

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

iOS 逆向学习 - iOS Architecture Media Layer

是 iOS 架构中的第二层,主要负责处理多媒体相关的功能,包括图像、音频、视频、动画、2D/3D 渲染等。在 iOS 开发中,这一层提供了高效的框架和 API,让开发者可以轻松实现多媒体应用。是 iOS 应用开发中处理多媒体的核心部分,它提供了丰富的框架和工具,帮助开发者轻松实现图形渲染、音视频处理和动画效果。

qq_45797625的博客 1703

系统学习iOS动画—— BahamaAirLogin(Layer 动画)

系统学习iOS动画—— BahamaAirLogin(Layer 动画) 在我之前到文章 —— 系统学习iOS动画—— BahamaAirLogin(UIKit动画) 中,用的是UIView.animate来进行alpha的变化实现添加透明度变化动画。layer 动画的工作方式很像UIView 动画;只需在定义的时间段内,在起始值和结束值之间设置属性的动画,并让Core Animation处理其间的渲染。然而,layer动画比UIView动画有更多的可动画属性;在设计效果时,这给了开发者很多选择和灵活性。许

LinShunIos的博客 456
上一篇: mac终端命令大全介绍
下一篇: iOS- 指压即达,如何集成iOS9里的3D Touch
iOSZhong
博客等级 码龄11年 1粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值