From: http://blog.csdn.net/wzzvictory/article/details/10076323
Original wangzz address: Success! These attributes of uiview have puzzled me for a while. By reading official documents, stackoverflow and other online resources, I have some understanding of them and I will share them with you. If your understanding is incorrect, please note that. 1. The Alpha LCD is composed of pixels, each of which can display a color value consisting of rgba. Where a indicates transparency Alpha, and Alpha in uiview is a floating point value with a value range of 0 ~ 1.0, indicating that from completely transparent to completely opaque. After the Alpha value is set to 0: 1. The current uiview and subview are hidden, regardless of the Alpha value of the subview. 2. The current uiview will be removed from the responder chain, and the next one in the responder chain will become the first responder. The default value of Alpha is 1.0. In addition, when the Alpha value is changed, the animation effect is implemented by default, because the layer is represented by calayer in core animation in cocoa, and the animation effect is an implicit animation of calayer. Of course, there are also ways to disable the animation effect, so I will not talk about it here. If you are interested, you can continue to follow up on subsequent blogs. 2. Hidden this attribute is a bool value, which indicates whether the uiview is hidden. The default value is no. When the value is set to yes: 1. The current uiview and subview are hidden, regardless of the value of the subview hidden. 2. The current uiview will be removed from the responder chain, and the next one in the responder chain will become the first responder. In short, the display effect is the same as that when Alpha is 0. The specific differences between the two are unclear. If you know anything, I hope you will not be enlightened! 3. the opaque attribute is a bool value. The default value of uiview is yes, but the default values of uibutton and other sub-classes are no. Opaque indicates whether the current uiview is not transparent, but the funny thing is that it does not determine whether the current uiview is not transparent. For example, if you set opaque to no, the uiview is still visible (as mentioned above, whether visible is determined by the Alpha or hidden attribute). If no is used, it indicates transparent. Should this be invisible? For more information, see: As mentioned above, each pixel in the monitor can display a color value consisting of rgba color space. For example, there are two color blocks in red and green layers, that is, for the pure red and green parts, the pixels at the corresponding position only need to be displayed in red or green. The corresponding rgba is (,) and, the GPU responsible for graphic display requires a small amount of computing to determine the display content corresponding to the pixel. The problem is that red and green have overlapping parts, and the color of their intersection is yellow. How does the yellow color come from here? Originally, the GPU mixed the layers by the colors of layers 1 and 2 to calculate the color of the mixed part. The optimal calculation formula is as follows:
R = S + D * (1-SA)
Here, r indicates the color of the mixed result, S is the source color (in the upper layer of the Red Layer 1), D is the target color (in the lower layer of the green Layer 2 ), sa is the Alpha value of the source color, that is, transparency. All S and d colors in the formula are assumed to have multiplied their transparency in advance.
After knowing the basic principles of layer mixing, let's go back to the topic and talk about the role of the opaque attribute. After the opaque attribute of uiview is set to yes, the formula is changed:
R = s
That is, the results are the same no matter why d. Therefore, the GPU will not perform any computation synthesis, and does not need to consider anything below it (because it is blocked), but simply copy from this layer. This saves considerable GPU workload. From this point of view, the real use of the opaque attribute is to provide a performance optimization switch for the drawing system!
According to the previous logic, when the opaque attribute is set to yes, the GPU will not use the layer color synthesis formula to synthesize the true color value. Therefore, if opaque is set to yes and the Alpha attribute of the corresponding uiview is not 1.0, unexpected situations may occur. This is clearly stated in the official documentation by Apple: an opaque view is expected to fill its bounds with entirely opaque content-that is, the content shoshould have an alpha value
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 shoshould always set the value of this property
NOIf the view is fully or partially transparent. Remember !!!! 4. When the Alpha attribute of uiview is set to 0 or hidden is set to yes, the current uiview and its sub-uiview become invisible, at the same time, it will not respond to Event Events. Note that the relationship here is or, that is, as long as one of them is set, it will have this effect, regardless of the value of another attribute.
Relationships and differences between alpha, hidden, and opaque attributes of uiview