您的位置:首页 > 产品设计 > UI/UE

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

2016-08-24 15:26 507 查看

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

首先放结论

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

有疑惑的同学继续看

一、alpha

alpha:

1  不透明
0  透明


透明之后:

当前的UIView和subview都会被隐藏,而不管subview的alpha值为多少。

当前UIView会从响应者链中移除,而响应者链中的下一个会成为第一响应者

二、hidden

hidden

YES 隐藏
NO  不隐藏


隐藏之后

当前的UIView和subview都会被隐藏,而不管subview的hidden值为多少。

当前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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: