Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is UIView's opaque property with a value of YES in conflict with its backgroundColor property with a value of [UIColor clearColor]?

Tags:

ios

uikit

uiview

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?

like image 229
Emily Avatar asked Aug 18 '11 05:08

Emily


2 Answers

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.

like image 194
David Hodge Avatar answered Nov 09 '22 16:11

David Hodge


No, it shouldn't be. It should act clear. The color clear is completely opaque, if that even makes sense. It won't show up black or white or anything else if you change its alpha. It will be clear.

like image 41
Jack Humphries Avatar answered Nov 09 '22 17:11

Jack Humphries