@fiy-fish
2016-12-04T09:56:34.000000Z
字数 2062
阅读 2929
iOS
Alpha(不透明度)
1.取值范围0-1.0,表示完全透明和完全不透明
2.传递性,会传递给此UIView 的subviews,这些subviews具有和此UIView相同的alpha值
3.具有动画效果,alpha = 0时,会有隐藏动画,故,这个属性可以用来做隐藏动画效果
hide
在动画块中没有动画效果4.当alpha = 0时,接收事件响应 而hide = yes
不接受
注意:
1.UIView
的backgroudColor
的alpha 值不会传递到subviews.
2. clear color 的alpha值就是0;
3.UIView
的alpha
值会影响backgroudColor
的alpha
值。 如self.View.alpha=0.8
,self.view.backgroudColor.alpha=0.5
则backgroudColor
的最终alpha
值为0.8*0.5 = 0.4
Hidden(影藏)
Opaque (不透明的)
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.
You only need to set a value for the opaque property for subclasses of UIView that draw their own content using the drawRect: method. The opaque property has no effect for system provided classes such as UIButton, UILabel, UITableViewCell, etc.
翻译一下:
使用opaque
可以提高系统的视图绘制性能,当opaque = yes
时,系统可以快速高效的绘制视图,这个时候view的alpha一定等于1
当view.alpha
小于1时,opaque
一定要设置为NO
,否则会发生意想不到的后果
1.opaque
默认为YES
,此时view.alpha=1
2.view,alpha
小于1时,opaque一定要设置为NO
屏幕绘制的知识
屏幕上的每个像素点都是通过RGBA值(Red、Green、Blue三原色再配上Alpha透明度)表示的
当纹理(UIView在绘图系统中对应的表示项)出现重叠时,GPU会按照Result = Source + Destination * (1 - SourceAlpha)公式计算重叠部分的像素。
Result是结果RGB值,Source为处在重叠顶部纹理的RGB值,Destination为处在重叠底部纹理的RGB值。
当SourceAlpha为1时,绘图系统认为下面的颜色全部被遮盖住了,Result=Source,
如果Source的Alpha不为0,上下层颜色就会进行合成
所以opaque默认设置YES,提升绘制性能
如果开发中UIView是不透明的,opaque设置为YES,
如果opaque设置NO,那么Alpha应该小于1.
alpha支持animation, hidden和opaque不支持
hidden开销小,alpha=0透明开销大,如果效果一样,用hidden好一点.
hideen的时候view是不接收事件的,但alpha为0接收
当把View设置为透明的背景时,一般把opaque设置为NO,可以减少开销,对内存也好.