gpt4 book ai didi

ios - 为什么 UIGraphicsGetCurrentContext() 在全局可用?

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:30 25 4
gpt4 key购买 nike

来自 Apple iOS Documentation #UIGraphicsGetCurrentContext : "在 iOS 4 及更高版本中,您可以从应用程序的任何线程调用此函数。"

还有,为什么方法调用是C函数格式UIGraphicsGetCurrentContext() 而不是 Objective-C 消息格式 [UIView UIGraphicsGetCurrentContext]

最佳答案

iOS 上有一些 API 是通过 C 而不是 ObjC 对象访问的。用于绘图的 CoreGraphics(所有 CG* 函数)是最重要的函数之一。

直接绘图通常在 CGContextRef 中完成,它表示图形上下文。 UIKit 保留一堆用于绘图的上下文(通常您不会在当前上下文之外进行太多交互)。此堆栈由全局 C 函数访问,因为您可以从任何地方使用它们。通常,它们是从 drawRect: 内部访问的,但您可以在其他地方使用此堆栈。 Per the docs :

If you are not using a UIView object to do your drawing, however, you must push a valid context onto the stack manually using the UIGraphicsPushContext function.

关于ios - 为什么 UIGraphicsGetCurrentContext() 在全局可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16258886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com