刚看到代码中有大量的xx.backgroundColor = [UIColor clearColor];html
(1)很好奇,默认的背景色是什么值?ios
官方给出的:默认为nil,此时背景是透明的。而后clearColor的备注也写明了:“0.0 white, 0.0 alpha”(白色,但alpha为0),因此我感受代码中设置clearColor的代码能够去掉,除非此举是为了reset背景色。app
(2)结束了这个问题后,想到了UIView有个属性是opaque,若是此属性设置为YES,也就是不透明,可是默认背景色是透明的,那。。。。会发生什么?ide
opaque属性默认为YES,这点本身没有理解透彻,若是是YES,那为何叠加的View会彻底被看到呢?跟背景色的默认值是否是冲突了呢?翻看官方文档后发现:this
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.spa
opaque为YES的视图的内容区域必须不透明:内容的alpha值须要为1。若是设置了opaque属性为YES,但内容中有部分透明或者所有透明,结果会是没法预期的。这样最好仍是要设置为NO。.net
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.htm
opaque属性只须要对继承自UIView的、使用drawRect:进行绘制内容的类(自定义类)中使用,对系统提供的类,例如UIButton, UILabel, UITableViewCell,等,使用此属性,是没有效果的。对象
这下明白了,这个属性更可能是为drawRect:方法绘制出内容的对象准备的,若是更多的是对系统提供控件的使用,通常状况下咱们用不到。blog
而后我又看到了一篇相关文章,顺便延伸一下:
原文地址:http://blog.csdn.net/wzzvictory/article/details/10076323
文章讲述了hidden、alpha、opaque的区别,其中说到了:
alpha为0和hidden为YES时,当前UIView会从响应者链中移除,而响应者链中的下一个会成为第一响应者,这一点比较有用
做者还提到了,alpha设置为0和hidden为YES有什么区别,我知道的是,在Windows Phone开发中,前者是须要CPU或GPU绘制的,然后者是不须要的,在iOS上是否如此,也但愿你们不吝赐教!