Is UIView's opaque property with a value of YE

2019-02-12 14:31发布

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?

标签: ios uiview uikit
2条回答
我命由我不由天
2楼-- · 2019-02-12 14:41

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.

查看更多
你好瞎i
3楼-- · 2019-02-12 15:01

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.

查看更多
登录 后发表回答