Core Animation学习笔记—第二节Setting up Layer Objects

各位iOS开发大佬们好:
我是一名Swift+SwiftUI栈的iOS小白,目前还在上大三,最近准备实习,面试的过程中发现现在大公司很多还在用OC + UIKit的技术栈,OC我还在考虑要不要学,目前想先把UIKit学完,这是我在官网学习UIKit英文文档时摘录的本人认为的重点,如果你们也觉得对你们有用的话欢迎持续关注,我大概一天更一节,有事除外。格式什么的我也就不做了,翻译都是我自己翻译的,哪里不对欢迎在评论区指正,感谢各位大佬支持

今天2021年12月2日
这一章叫做Setting up Layer Objects

iOS默认自动启用layer,但在OS X中还是需要显式的启用它以获得更好的性能表现
Link against the QuartzCore framework. (iOS apps must link against this framework only if they use Core Animation interfaces explicitly.)
Enable layer support for one or more of your NSView objects by doing the following:
For views you create programmatically, call the view’s setWantsLayer: method and pass a value of YES to indicate that the view should use layers.
在OS X中需要做以下工作来显式启用Layer
与QuartzCore链接
调用setWantsLayer: 方法,传入一个YES来启用你NSView对象的layer

可以更换与视图关联的layer类型以获得更方便的操作和可能更好的性能

在iOS中可以通过重写视图的layerclass方法为视图返回一个其他类型的layer
以下三种情况是你可能会去更改layer类型的

Your view draws content using Metal or OpenGL ES, in which case you would use a CAMetalLayer or CAEAGLLayer object.
There is a specialized layer class that offers better performance.
You want to take advantage of some specialized Core Animation layer classes, such as particle emitters or replicators.
视图使用Metal或OpenGL ES绘图时,可能会需要CAMetalLayer或CAEAGLLayer对象
其他提供更高性能的layer类型
使用一些专用CALayer例如particle emitters 或者 replicators

通过重写NSView的makeBackingLayer方法来更改默认layer类,实现时创建并返回你需要的layer类型

A layer-hosting view is an NSView object for which you create and manage the underlying layer object yourself. You might use layer hosting in situations where you want to control the type of layer object associated with the view. For example, you might create a layer-hosting view so that you can assign a layer class other than the default CALayer class. You might also use it in situations where you want to use a single view to manage a hierarchy of standalone layers.

托管图层视图是一个NSView对象,你需要自己创建并管理底层layer对象,在你需要控制视图layer的类型时,或在您想使用单个视图来管理独立图层的层次结构的情况下可以使用它。

When you call the setLayer: method of your view and provide a layer object, AppKit takes a hands-off approach to that layer. Normally, AppKit updates a view’s layer object but in the layer-hosting situation it does not for most properties.
当调用视图的setLayer:方法并提供图层对象时,AppKit不会对layer进行操作。AppKit会更新视图的图层对象,但在图层托管的情况下,大多数属性不会更新视图的图层对象。

If you choose to host layers yourself, you must set the contentsScale property yourself and provide high-resolution content at appropriate times.
如果选择自己控制layer,你需要自己设置contentsScale 属性,并在任何时候提供高分辨率的内容
CALayer是所有layer的基类,以下是衍生layer

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值