UIView 的值为 YES 的 opaque 属性是否与其值为 [UIColor clearColor] 的 backgroundColor 属性冲突?
例如代码:
view.opaque = YES;
谁能
view.backgroundColor = [UIColor clearColor];
解释一下这一点?
编辑:
如文档所示:
尽可能将视图声明为不透明
UIKit 使用每个视图的 opaque 属性来确定该视图是否可以优化合成操作。对于自定义视图,将此属性的值设置为 YES 会告诉 UIKit 它不需要在视图后面呈现任何内容。较少的渲染可以提高绘图代码的性能,并且通常受到鼓励。当然,如果您将 opaque 属性设置为 YES,您的视图必须用完全不透明的内容完全填充其边界矩形。
opaque属性用于确定视图是否可以优化合成操作。
所以问题是:
如果我设置了 view.opaque = YES
和 view.backgroundColor = [UIColorclearColor]
,前者提高了性能,后者怎么样?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
opaque 标志用于渲染优化。如果在视图不应不透明时将其设置为 YES,那么如果您确实希望通过视图看到某些内容,则可能会出现意外的渲染。
我的理解是,有时会检查不透明标志以查看是否应该检查 alpha 值。
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.
不,不应该。它应该表现得很清楚。如果这有意义的话,透明的颜色是完全不透明的。如果你改变它的阿尔法,它不会显示黑色或白色或其他任何东西。一切都会清楚的。
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.