ios - view.alpha = 0 与 view.hidden = YES 有什么影响?

标签 ios cocoa-touch transparency

透明度是邪恶的,在 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/

相关文章:

object - 加工中的透明纹理形状

ios - 使用 Swift 在 ScrollView 中显示警报

ios - Pod :Module 的未定义局部变量或方法

ios - 圆弧 : how to inject custom dealloc IMP in object which in turn calls original dealloc without causing malloc error

objective-c - 如何旋转 UIWebView 的内容?

python - 如何在 pyglet/pyopengl 中使用透明层而不是纯色来清除屏幕

ios - 使用 CIFilter 进行渲染时,实时摄像机被拉伸(stretch)。 - swift 4

ios - 使用 STTwitterAPI 使用 twitter 登录一次

ios - 如何启动单个计时器并从多个 View 访问它?

qt - 如何在Qt中设置QTableWidget背景透明?