aphicsGetCurrentContext时是否有任何性能损

aphicsGetCurrentContext时是否有任何性能损

本文介绍了重复调用UIGraphicsGetCurrentContext时是否有任何性能损失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义 drawRect 函数构建 UIView 。这是一个相当复杂的视图,需要绘制许多不同的项目。我基本上已将其分解为每个需要绘制的项目的一个函数。

I'm building a UIView with a custom drawRect function. This is a fairly complex view, with a number of different items that need to be drawn. I've basically broken it down into one function per item that needs to be drawn.

我想知道的是我应该通过我的 CGContextRef吗从 UIGraphicsGetCurrentContext()获得的,作为每个函数的参数,还是可以在每个函数的开头调用它?后一种选择对我来说看起来更整洁,但是我想知道是否会有很多性能损失?

What I'm wondering is should I pass my CGContextRef, obtained from UIGraphicsGetCurrentContext(), as a parameter to each function, or can I just call it at the start of each function? The latter option looks neater to me, but I am wondering if there is much of a performance penalty?

推荐答案

除非您正在各处保存/恢复上下文。无论如何,从该方法获取上下文很可能永远不会成为瓶颈。

It's the same, unless you are saving/restoring context all around. In any way, getting the context from that method will, most probably, never be the bottleneck.

我建议,如果您不保存和恢复状态,则可以使用 UIGraphicsGetCurrentContext()。但是,如果您确实要保存状态,则应该通过此代码,因为这样可以更轻松地读取代码。

I suggest that if you are not saving and restoring states, you could use the UIGraphicsGetCurrentContext(). However, if you are indeed saving state, you should pass this one since it would be easier to read your code.

我想这是样式问题...

It's a matter of style I guess...

这篇关于重复调用UIGraphicsGetCurrentContext时是否有任何性能损失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 05:24