各位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

最低0.47元/天 解锁文章
6514

被折叠的 条评论
为什么被折叠?



