Ios – Is UIView’s opaque property with a value of YES in conflict with its backgroundColor property with a value of [UIColor clearColor]

iosuikituiview

such as the code:

view.opaque = YES;

and

view.backgroundColor = [UIColor clearColor];

any one who can explain something about this?

EDIT:

as the document shows:

Declare Views as Opaque Whenever Possible

UIKit uses the opaque property of each view to determine whether the view can optimize compositing operations. Setting the value of this property to YES for a custom view tells UIKit that it does not need to render any content behind your view. Less rendering can lead to increased performance for your drawing code and is generally encouraged. Of course, if you set the opaque property to YES, your view must fills its bounds rectangle completely with fully opaque content.

opaque property is used for determining whether the view can optimize compositing operations.

so the question is:

if i set view.opaque = YES and view.backgroundColor = [UIColor clearColor],the former increased performance,how about the latter?

Best Answer

The opaque flag is used as an optimization for rendering. If you set it to YES when the view shouldn't be opaque you can get unexpected rendering if you actually want things to be visible through the view.

My understanding is that the opaque flag is sometimes checked to see if alpha value should even be checked.

Related Topic