iOS development-alpha,hidden and opaque differences

Source: Internet
Author: User



The three attributes in the UIView are much more, especially when the alpha and opaque are not very well separated, and are slightly sorted out:


Alpha (opacity)


Alpha is the opacity, the property is a floating-point type of value, the value range from 0 to 1.0, indicating from completely transparent to completely opaque, its characteristics are the alpha value of the current UIView is 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.





  UIView *view=[[UIView alloc]initWithFrame:CGRectMake(30, 100, CGRectGetWidth(self.view.bounds)-60, 150)];
    [view setBackgroundColor:[UIColor redColor]];
    [view setAlpha:0.5];
    [self.view addSubview:view];
    
    UIView *childView=[[UIView alloc]initWithFrame:CGRectMake(20, 30, 100, 80)];
    [childView setBackgroundColor:[UIColor blueColor]];
    [view addSubview:childView];








Setting the alpha value of BackgroundColor affects only the background of the current UIView and does not affect all of its subview. Clear color is the alpha of BackgroundColor 1. 0. The alpha value affects the final alpha of the backgroundcolor, Assuming that the alpha of UIView is 0.8,backgroundcolor 0.5, the final alpha of the backgroundcolor is 0.4 (0.8*0.5).


Hidden (Hidden)


hidden Indicates whether UIView is hidden, hidden is set to Yes to indicate that all subview of the former 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 ~





The 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 Drawin G Operations and improve performance. If set to NO, the drawing system composites the view normally and other content. The default value of the IS YES. An opaque view are expected to fill their bounds with entirely opaque content-that are, 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. You should always set the value of this property to NO if the view is fully or partially transparent. You are need to set a value for the opaque property for subclasses of UIView that draw their own content using the Drawre Ct:method. The Opaque property has a no effect for system provided classes such as UIButton, 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: Https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref /occ/instp/uiview/opaque



iOS development-alpha,hidden differs from opaque


Related Article

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.