本文介绍了UIView性能:不透明,backgroundColor,clearsContextBeforeDrawing?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用白色背景色的超级视图中显示带有UIImageView的不透明PNG.最好的性能是什么?

I'm displaying opaque PNGs with UIImageViews inside of a superview with a white background color. What's best for performance?

opaque = NObackgroundColor = nilclearsContextBeforeDrawing = YES.

  1. UIView类参考:backgroundColor 说,"[nil]产生透明的背景色.如果我设置 UIViewopaque属性设置为YES,我是否还必须将其backgroundColor设置为[UIColor clearColor],还是这是多余的代码行&处理不必要吗?即[UIColor clearColor]是否被认为是不透明的(不透明)?

  1. UIView Class Reference: backgroundColor says, "[nil] results in a transparent background color." If I set a UIViews opaque property to YES, must I also set its backgroundColor 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和不透明属性
  • Similar Questions

    • 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
    • 推荐答案

      假定您的PNG始终填充整个UIImageView,则应使用以下方法获得最佳性能:

      Assuming that your PNGs always fills the entire UIImageView, you should get the best performance using:

      opaque = YESclearsContextBeforeDrawing = 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 = YESclearsContextBeforeDrawing = YESbackgroundColor匹配您需要的任何内容.在这种情况下[UIColor whiteColor].

      opaque = YES, clearsContextBeforeDrawing = YES, and backgroundColor matching whatever you need. In this case [UIColor whiteColor].

      这篇关于UIView性能:不透明,backgroundColor,clearsContextBeforeDrawing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 10:07