问题描述
我正在用白色背景色的超级视图中显示带有UIImageView
的不透明PNG.最好的性能是什么?
I'm displaying opaque PNGs with UIImageView
s inside of a superview with a white background color. What's best for performance?
opaque = NO
,backgroundColor = nil
,clearsContextBeforeDrawing = YES
.
-
UIView类参考:backgroundColor 说,"[
nil
]产生透明的背景色.如果我设置UIView
的opaque
属性设置为YES
,我是否还必须将其backgroundColor
设置为[UIColor clearColor]
,还是这是多余的代码行&处理不必要吗?即[UIColor clearColor]
是否被认为是不透明的(不透明)?
UIView Class Reference: backgroundColor says, "[
nil
] results in a transparent background color." If I set aUIView
sopaque
property toYES
, must I also set itsbackgroundColor
to[UIColor clearColor]
, or is that extra line of code & processing unnecessary? I.e., is[UIColor clearColor]
considered opaque (not transparent)?
clearsContextBeforeDrawing
的值对不透明视图有影响吗?
Does the value of clearsContextBeforeDrawing
matter for opaque views?
在UIView.h
中对clearsContextBeforeDrawing
的注释说,对于不透明的视图,它将被忽略.
The comments for clearsContextBeforeDrawing
in UIView.h
say it's ignored for opaque views.
但是, UIView类参考:clearsContextBeforeDrawing 说:
是哪个?
类似问题
- 是值为YES的UIView的opaque属性与其值为[UIColor clearColor]的backgroundColor属性冲突?
- Cocoa/iPhone:BackgroundColor和不透明属性
- Is UIView's opaque property with a value of YES in conflict with its backgroundColor property with a value of [UIColor clearColor]?
- Cocoa/iPhone: BackgroundColor and Opaque Properties
Similar Questions
推荐答案
假定您的PNG始终填充整个UIImageView
,则应使用以下方法获得最佳性能:
Assuming that your PNGs always fills the entire UIImageView
, you should get the best performance using:
opaque = YES
,clearsContextBeforeDrawing = NO
.在此模式下,backgroundColor
无关紧要.像素只需替换为新的图像数据即可.
opaque = YES
, clearsContextBeforeDrawing = NO
. In this mode backgroundColor
is irrelevant. The pixels are simply replaced with the new image data.
对于单色背景上的透明PNG,最快的是:
For transparent PNGs on a single-color background, the fastest will be:
opaque = YES
,clearsContextBeforeDrawing = YES
和backgroundColor
匹配您需要的任何内容.在这种情况下[UIColor whiteColor]
.
opaque = YES
, clearsContextBeforeDrawing = YES
, and backgroundColor
matching whatever you need. In this case [UIColor whiteColor]
.
这篇关于UIView性能:不透明,backgroundColor,clearsContextBeforeDrawing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!