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.