UIView Alpha, hidden, opaque in depth

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/wzzvictory/article/details/10076323

UIView These properties puzzled me for a while, by looking through the official documents and StackOverflow and other online resources, they have a certain understanding, is now shared. If you understand the mistake, please also point out.   Alpha LCD is made up of pixel dots, each pixel can display a color value composed of the Rgba color space. A is a representation of the transparency Alpha,uiview Alpha is a floating-point value, and the range of values is 0~1.0, from full transparency to completely opaque. When the value of Alpha is set to 0:1, the current UIView and Subview will be hidden, regardless of the alpha value of Subview. 2. The current uiview is removed from the responder chain, and the next one in the responder chain becomes the first responder alpha with the default value of 1.0. Also, when you change the alpha value, it is animated by default, because the layer is represented in cocoa by the Calayer in core animation, which is an implicit animation of Calayer. Of course there are ways to disable this animation effect, in this is not much, interested students can continue to follow the blog.   Hidden This property is a bool value, which is used to indicate whether the UIView is hidden and the default value is No. When the value is set to Yes: 1, the current UIView and Subview will be hidden, regardless of the subview hidden. 2. The current uiview will be removed from the responder chain, and the next in the responder chain will be the first responder in summary, the same as Alpha 0 o'clock. What is the difference between the two is not clear, if you have to know also look at the liberal enlighten!   Opaque The property is a bool value, the default value for UIView is yes, but the default value for subclasses such as UIButton is No. Opaque indicates whether the current UIView is opaque, but the funny fact is that it doesn't determine if the current uiview is opaque, such as if you set opaque to No, the UIView is still visible (as stated above, whether or not visible is determined by alpha or hidden properties) , it should be said that no is transparent, it should be invisible? Sell a Xiaoguanzi, look first: In the front, each pixel in the display can display a color value composed of the Rgba color space, such as the red and green two layer color blocks, for the non-intersecting part, that is, the pure red and green parts, the corresponding location of the pixel point only need to display a simple red or green, The corresponding Rgba is (1,0,0,1) and (0,1,0,1) on the line, the GPU responsible for graphics display needs a small amount of computation to determine the pixel corresponding to the display content. The problem is red and green and intersect.The color of the intersection is yellow. How does the yellow here come from? Originally, the GPU uses layer one and layer two colors for layer blending to calculate the color of the mixed part, the most ideal formula is as follows:

R = S + D * (1–SA)

where r is the color of the blend result, S is the source color (one on the upper layer of red), and D is the target color (located on the lower layer of green layers two), and the SA is the alpha value of the source color, that is, transparency. All the S and D colors in the formula are assumed to have been pre-multiplied by their transparency.

Once you know the fundamentals of layer blending, go back to the point of opaque properties. When the opaque property of UIView is set to Yes, the formula, which is the SA value of 1, is changed to the following formula:

R = S

That is, regardless of D why, the result is the same. So the GPU will not do any computational compositing, and it does not need to consider anything underneath it (because it is obscured by it), but simply copy it from this layer. This saves the GPU quite a lot of work. Thus, the real use of the opaque attribute is to provide a performance optimization switch for the drawing system!

By the previous logic, when the opaque property is set to Yes, the GPU will no longer use the layer color composition formula to synthesize true color values. Therefore, if opaque is set to Yes, and the alpha attribute of the corresponding UIView is not 1.0, there will be unforeseen circumstances, which Apple has clearly stated in the official documentation: an opaque view was expected to fill its Bounds with entirely opaque content-that is, the content should has an alpha value of 1.0. If The view is opaque and either does isn't fill its bounds or contains wholly or partially transparent content,the results is unpredictable. Should always set the value of the NOIf the view is fully or partially transparent. everyone remember!!!! Finally, when the alpha attribute of the UIView is set to 0, or the hidden is set to Yes, the current UIView and the child UIView it contains will become invisible and will no longer respond to event events. Note that this is a relationship, that is, as long as one of the settings has this effect, regardless of the value of the other property.

UIView Alpha, hidden, opaque in depth

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.