[BS-17] iOS development-alpha,hidden and opaque differences

Source: Internet
Author: User



The UIView control has the three common properties of Alpha,hidden and opaque, and the UIView control backgroundcolor is in Rgba, so the background color also has an alpha (the palette in storyboard is displayed as opacity )。 These properties are easy to confuse when used, especially when the alpha and opaque are not very well separated, slightly sorted out:


Alpha (Opacity)


Alpha is an opacity, property is a value of floating-point type, with a range from 0 to 1.0, which means that from fully transparent to completely opaque, whose attributes have the current UIView alpha value inherited by all of its subview. The alpha value affects the animation of UIView with all its subview,alpha. When Alpha is 0 o'clock, the effect is the same as hidden, but Alpha is primarily used to implement a hidden animation effect, and setting hidden to Yes in the animation block is not animated.



Setting the Alpha (Opacity) value in the Rgba of BackgroundColor only affects the background of the current UIView and does not affect all its subview. Clear color is BackgroundColor's alpha (Opacity) is 0. However, setting the alpha value of the UI control affects the final alpha of its child view, assuming that the alpha of UIView is 0.8 and the child view has an alpha of 0.5, then the child view eventually has an alpha of 0.4 (0.8*0.5).















The following printing results show that the opacity value set in the storyboard palette is the alpha value of RGBA when setting Uicolor with code. This value is only for color colors themselves and does not affect the transparency alpha of the child views.








Hidden (Hidden)


Hidden indicates whether UIView is hidden, hidden is set to Yes to indicate that all subview of the current UIView are also hidden, ignoring subview hidden properties. Hidden all subview will be hidden if set to Yes. UIView is also removed from the current responder event after it is hidden.


Opaque


Opaque is also the opacity of the current UIView, setting whether or not after the display of the UIView has no effect, the official document means that the simple point is that the opaque default is yes, if alpha is less than 1, then you should set the opaque set to No, However, if Alpha is set to No for 1,opaque, the result is unpredictable ~





12345 This property provides a hint to the drawing system asto how it should treat the view. If setto YES, the drawing system treats the view asfully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If setto NO, the drawing system composites the view normally with other content. The defaultvalue of thisproperty isYES.An opaque view isexpected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. If the view isopaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always setthe value of thisproperty to NO ifthe view isfully or partially transparent.You only need to seta value forthe opaque property forsubclasses of UIView that draw their own content usingthe drawRect: method. The opaque property has no effect forsystem provided classes such asUIButton, UILabel, UITableViewCell, etc.





If you know opaque, you need a bit of screen drawing knowledge, and each pixel on the screen is represented by the RGBA value (Red, Green, Blue primaries, and alpha transparency), when the texture (UIView in the drawing system) overlaps. The GPU calculates the pixels of the overlapping portions according to the result = Source + Destination * (1-sourcealpha) formula.



Result is the resulting RGB value, which is the RGB value of the top texture that is overlapping, and destination is the RGB value of the texture at the bottom of the overlay.



When Sourcealpha is 1 o'clock, the drawing system thinks that the following colors are all covered up, result=source, if the Source Alpha is not 0, the upper and lower layers of color will be synthesized, so the opaque default setting Yes, improve the drawing performance, If UIView is opaque in development, opaque is set to Yes, and if opaque set no, then alpha should be less than 1.






Reference Source: Http://www.cnblogs.com/xiaofeixiang/p/5149765.html?utm_source=tuicool&utm_medium=referral



[BS-17] iOS development-alpha,hidden and opaque differences


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.