开发者

Why opaque views are more effective on iPhone?

I tried to find other reasons why opaque views are better than transparent. However, the only sensible reason I came up with is that the view behind the opaque one doesn't need 开发者_运维技巧to draw its content at that place.

Is this a wrong assumption and are there other good reasons?

Thanks.


This is the right assumption. Directly from Apple documentation:

opaque

A Boolean value that determines whether the receiver is opaque.

@property(nonatomic, getter=isOpaque) BOOL opaque

Discussion

This property provides a hint to the drawing system as to how it should treat the view. If set to YES, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set to NO, the drawing system composites the view normally with other content. The default value of this property is YES.

An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always set the value of this property to NO if the view is fully or partially transparent.


Aside from being able to avoid drawing the background view, there are a few other reasons it's faster, related to compositing:

1) There's no need to blend the foreground and background views, which saves some math done on every pixel

2) If the view moves, its pixels can simply be blitted to their new locations without any redrawing at all. This is a huge deal for scrolling performance, even on desktop computers, let alone mobile devices.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜