iOS-UIView的alpha、hidden和opaque -区别

来源:互联网 发布:知乎和豆瓣 人群定位 编辑:程序博客网 时间:2024/05/21 14:04

iOS-UIView的alpha、hidden和opaque -区别

首先放结论

如果你的View没有任何透明(也就是alpha==1),尽管把opaque==YES.这样会加快GPU的处理速度


有疑惑的同学继续看


一、alpha

alpha:

           1  不透明           0  透明               

透明之后:

  1. 当前的UIView和subview都会被隐藏,而不管subview的alpha值为多少。
  2. 当前UIView会从响应者链中移除,而响应者链中的下一个会成为第一响应者
二、hidden

hidden

    YES 隐藏    NO  不隐藏

隐藏之后

  1. 当前的UIView和subview都会被隐藏,而不管subview的hidden值为多少。
  2. 当前UIView会从响应者链中移除,而响应者链中的下一个会成为第一响应者
三、opaque

opaque

    YES 不透明    NO  透明 

我个人关于opaque==NO解释:

该View的父View的layer层将影响自身.

什么意思呢?绘画过同学know,RED+GREEN=YELLOW

对吧?:)

打个比方父View的Background为RED,自身的Background设置为GREEN

最后显示的其实是YELLOW(RED+GREEN),也就是黄色

另外需要注意的是opaque和alpha只能有一个!=1


苹果官方说明

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.

0 0
原创粉丝点击