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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值