CALayer,web开发学习过程

本文详细介绍了CALayer在iOS和Web前端开发中的作用,包括管理视觉内容、几何信息、动画、渲染行为和层级结构,同时还提及了如何利用这些知识进行有效的自学路径和面试准备。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Overview


Layers 通常被用于去提供views的后备存储. A layer’s 的主要工作是管理您提供的视觉内容,但layer’s本身视觉属性可以设置,如背景颜色,边境,和阴影。除了管理视觉内容,该层还维护其内容的几何信息(比如它的位置、大小和变换),用于在屏幕上显示这些内容。修改layer的属性决定着你怎么样在layer几何内容上启动动画。对象封装一层一层的持续时间和节奏及其动画采用CAMediaTiming协议,它定义了层的计时信息。

如果这个layer是由View所创建的,那么这个 View将会自动成为 layer的委托对象,你不应该改变这种关系。因为层自己创建了自己,层你可以指定一个委托对象,并使用该对象提供 layer的动态内容 和执行其他任务。 layer 也有一个布局管理器对象(分配给layoutManager属性)来分别管理子视图的布局。

Symbols


Creating a Layer

+ layer

Creates and returns an instance of the layer object.

- init

Returns an initialized CALayer object.

- initWithLayer:

Override to copy or initialize custom fields of the specified layer.

Accessing Related Layer Objects

- presentationLayer

Returns a copy of the presentation layer object that represents the state of the layer as it currently appears onscreen.

- modelLayer

Returns the model layer object associated with the receiver, if any.

Accessing the Delegate

delegate

The layer’s delegate object.

Providing the Layer’s Content

contents

An object that provides the contents of the layer. Animatable.

contentsRect

The rectangle, in the unit coordinate space, that defines the portion of the layer’s contents that should be used. Animatable.

contentsCenter

The rectangle that defines how the layer contents are scaled if the layer’s contents are resized. Animatable.

- display

Reloads the content of this layer.

- drawInContext:

Draws the layer’s content using the specified graphics context.

Modifying the Layer’s Appearance

contentsGravity

A constant that specifies how the layer’s contents are positioned or scaled within its bounds.

opacity

The opacity of the receiver. Animatable.

hidden

A Boolean indicating whether the layer is displayed. Animatable.

masksToBounds

A Boolean indicating whether sublayers are clipped to the layer’s bounds. Animatable.

mask

An optional layer whose alpha channel is used to mask the layer’s content.

doubleSided

A Boolean indicating whether the layer displays its content when facing away from the viewer. Animatable.

cornerRadius

The radius to use when drawing rounded corners for the layer’s background. Animatable.

borderWidth

The width of the layer’s border. Animatable.

borderColor

The color of the layer’s border. Animatable.

backgroundColor

The background color of the receiver. Animatable.

shadowOpacity

The opacity of the layer’s shadow. Animatable.

shadowRadius

The blur radius (in points) used to render the layer’s shadow. Animatable.

shadowOffset

The offset (in points) of the layer’s shadow. Animatable.

shadowColor

The color of the layer’s shadow. Animatable.

shadowPath

The shape of the layer’s shadow. Animatable.

style

An optional dictionary used to store property values that aren’t explicitly defined by the layer.

allowsEdgeAntialiasing

A Boolean indicating whether the layer is allowed to perform edge antialiasing.

allowsGroupOpacity

A Boolean indicating whether the layer is allowed to composite itself as a group separate from its parent.

Accessing the Layer’s Filters

filters

An array of Core Image filters to apply to the contents of the layer and its sublayers. Animatable.

compositingFilter

A CoreImage filter used to composite the layer and the content behind it. Animatable.

backgroundFilters

An array of Core Image filters to apply to the content immediately behind the layer. Animatable.

minificationFilter

The filter used when reducing the size of the content.

minificationFilterBias

The bias factor used by the minification filter to determine the levels of detail.

magnificationFilter

The filter used when increasing the size of the content.

Configuring the Layer’s Rendering Behavior

opaque

A Boolean value indicating whether the layer contains completely opaque content.

edgeAntialiasingMask

A bitmask defining how the edges of the receiver are rasterized.

- contentsAreFlipped

Returns a Boolean indicating whether the layer content is implicitly flipped when rendered.

geometryFlipped

A Boolean that indicates whether the geometry of the layer and its sublayers is flipped vertically.

drawsAsynchronously

A Boolean indicating whether drawing commands are deferred and processed asynchronously in a background thread.

shouldRasterize

A Boolean that indicates whether the layer is rendered as a bitmap before compositing. Animatable

rasterizationScale

The scale at which to rasterize content, relative to the coordinate space of the layer. Animatable

contentsFormat

A hint for the desired storage format of the layer contents.

- renderInContext:

Renders the layer and its sublayers into the specified context.

Modifying the Layer Geometry

frame

The layer’s frame rectangle.

bounds

The layer’s bounds rectangle. Animatable.

position

The layer’s position in its superlayer’s coordinate space. Animatable.

zPosition

The layer’s position on the z axis. Animatable.

anchorPointZ

The anchor point for the layer’s position along the z axis. Animatable.

anchorPoint

Defines the anchor point of the layer’s bounds rectangle. Animatable.

contentsScale

The scale factor applied to the layer.

Managing the Layer’s Transform

transform

The transform applied to the layer’s contents. Animatable.

sublayerTransform

Specifies the transform to apply to sublayers when rendering. Animatable.

- affineTransform

Returns an affine version of the layer’s transform.

- setAffineTransform:

Sets the layer’s transform to the specified affine transform.

Managing the Layer Hierarchy

sublayers

An array containing the layer’s sublayers.

superlayer

The superlayer of the layer.

- addSublayer:

Appends the layer to the layer’s list of sublayers.

- removeFromSuperlayer

Detaches the layer from its parent layer.

- insertSublayer:atIndex:

Inserts the specified layer into the receiver’s list of sublayers at the specified index.

- insertSublayer:below:

Inserts the specified sublayer below a different sublayer that already belongs to the receiver.

- insertSublayer:above:

Inserts the specified sublayer above a different sublayer that already belongs to the receiver.

- replaceSublayer:with:

Replaces the specified sublayer with a different layer object.

Updating Layer Display

- setNeedsDisplay

Marks the layer’s contents as needing to be updated.

- setNeedsDisplayInRect:

Marks the region within the specified rectangle as needing to be updated.

needsDisplayOnBoundsChange

A Boolean indicating whether the layer contents must be updated when its bounds rectangle changes.

- displayIfNeeded

Initiates the update process for a layer if it is currently marked as needing an update.

- needsDisplay

Returns a Boolean indicating whether the layer has been marked as needing an update.

+ needsDisplayForKey:

Returns a Boolean indicating whether changes to the specified key require the layer to be redisplayed.

Layer Animations

- addAnimation:forKey:

Add the specified animation object to the layer’s render tree.

- animationForKey:

Returns the animation object with the specified identifier.

- removeAllAnimations

Remove all animations attached to the layer.

- removeAnimationForKey:

Remove the animation object with the specified key.

- animationKeys

Returns an array of strings that identify the animations currently attached to the layer.

Managing Layer Resizing and Layout

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

最后

技术是没有终点的,也是学不完的,最重要的是活着、不秃。零基础入门的时候看书还是看视频,我觉得成年人,何必做选择题呢,两个都要。喜欢看书就看书,喜欢看视频就看视频。最重要的是在自学的过程中,一定不要眼高手低,要实战,把学到的技术投入到项目当中,解决问题,之后进一步锤炼自己的技术。

技术学到手后,就要开始准备面试了,找工作的时候一定要好好准备简历,毕竟简历是找工作的敲门砖,还有就是要多做面试题,复习巩固。有需要面试题资料的朋友点击这里可以免费领取


[外链图片转存中…(img-BC53VWRk-1712085966005)]

[外链图片转存中…(img-aQfKitLu-1712085966005)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

[外链图片转存中…(img-bfDSsaSm-1712085966006)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

最后

技术是没有终点的,也是学不完的,最重要的是活着、不秃。零基础入门的时候看书还是看视频,我觉得成年人,何必做选择题呢,两个都要。喜欢看书就看书,喜欢看视频就看视频。最重要的是在自学的过程中,一定不要眼高手低,要实战,把学到的技术投入到项目当中,解决问题,之后进一步锤炼自己的技术。

技术学到手后,就要开始准备面试了,找工作的时候一定要好好准备简历,毕竟简历是找工作的敲门砖,还有就是要多做面试题,复习巩固。有需要面试题资料的朋友点击这里可以免费领取

[外链图片转存中…(img-zpasUR9k-1712085966006)]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值