透明度是邪恶的,在 iOS 设备上比在更重的机器上更是如此。因此,我想首先使用 view removeFromSuperView
,如果不适用 view.hidden=YES
,作为最后的手段 view.alpha=0
。但我其实不知道幕后发生了什么。有区别吗,尤其是后两者之间?
我有一个 UIView animateWithDuration:animations:completion:
场景,如果您在完成 block 中设置 hidden=YES,它将隐藏而不让动画 block 完成。因此我不得不求助于 alpha=0。
一个比另一个的惩罚是什么? 干杯,EP。
最佳答案
我不确定是否仍然绘制了 alpha 0.0 的 View 。检查文档库:
Hiding Views
To hide a view visually, you can either set its hidden property to YES or change its alpha property to 0.0. A hidden view does not receive touch events from the system. However, hidden views do participate in autoresizing and other layout operations associated with the view hierarchy. Thus, hiding a view is often a convenient alternative to removing views from your view hierarchy, especially if you plan to show the views again at some point soon.
我也在这里找到了这个答案 http://www.iphonedevsdk.com/forum/iphone-sdk-development/65525-whats-difference-between-alpha-0-hidden-yes.html
也就是说:
I believe that Cocoa Touch treats and alpha less than 0.02 as also being hidden, since below that alpha level it's invisible, and Apple's engineers decided that invisible controls should not be clickable.
Using an alpha value requires that the graphics hardware blend each pixel from the object with everything underneath. It's compute-intensive. The hidden flag, on the other hand, is a switch. If you turn it on, the OS knows it doesn't have to draw the object at all.
关于ios - view.alpha = 0 与 view.hidden = YES 有什么影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5146947/