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

发布于 2024-10-20 01:28:00 字数 335 浏览 2 评论 0原文

透明度是邪恶的,在 iOS 设备上比在重型机器上更是如此。因此,我认为如果不适用,首先使用view removeFromSuperView,然后再使用view.hidden=YES作为最后的手段view.alpha=0。但实际上我不知道幕后发生了什么。有区别吗,尤其是后两者之间?

我有一个 UIView animateWithDuration:animations:completion: 场景,如果您将 hide=YES 放在完成块中,它将隐藏而不让动画块完成。因此我必须求助于 alpha=0。

一方相对于另一方的处罚是什么? 干杯,EP。

Transparency is evil, on iOS devices even more so than on heavier machines. I therefore figured to use view removeFromSuperView first, if not applicable view.hidden=YES and as a last resort view.alpha=0. But I actually don't know what's going on behind the scenes. Is there a difference, especially between the latter two?

I have a UIView animateWithDuration:animations:completion: scenario, where if you put hidden=YES in the completion block, it will hide without letting the animation block finish. Therefore I have to resort to alpha=0.

What are the penalties of the one over the other?
Cheers, EP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧时模样 2024-10-27 01:28:00

我不确定是否仍绘制 alpha 0.0 的视图。检查文档库:

隐藏视图

要在视觉上隐藏视图,您可以将其隐藏属性设置为 YES 或将其 alpha 属性更改为 0.0。隐藏视图不接收来自系统的触摸事件。但是,隐藏视图确实参与自动调整大小以及与视图层次结构相关的其他布局操作。因此,隐藏视图通常是从视图层次结构中删除视图的便捷替代方法,特别是如果您计划很快再次显示视图。

我也在这里找到了这个答案 http://www.iphonedevsdk.com/forum/iphone-sdk-development/65525-whats-difference- Between-alpha-0-hidden-yes.html

这表示:

我相信 Cocoa Touch 将 alpha 小于 0.02 也视为隐藏,因为低于该 alpha 水平它是不可见的,并且 Apple 的工程师决定不可见的控件不应该是可点击的。

使用 Alpha 值要求图形硬件将对象中的每个像素与其下面的所有内容混合。它是计算密集型的。另一方面,隐藏标志是一个开关。如果您打开它,操作系统知道它根本不必绘制对象。

I am not sure that a view with alpha 0.0 is still drawn. Check the documentation library:

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.

I also have found this answer here http://www.iphonedevsdk.com/forum/iphone-sdk-development/65525-whats-difference-between-alpha-0-hidden-yes.html

That says:

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.

夜清冷一曲。 2024-10-27 01:28:00

alpha 为零的内容仍然会被绘制,但是隐藏的视图不会重新绘制到屏幕上。由于这种情况仅在视图发生变化时才会发生,因此差异应该微不足道。如果您遇到性能问题,我强烈建议使用时间分析器和核心动画工具进行分析。

Something with an alpha of zero, still is drawn, however a view that is hidden is not redrawn to the screen. Since this only happens when the view changes anyways, the difference should be insignificant. If you are experiencing performance issues, I would highly recommend profiling with the time profiler and core animation instruments.

诗酒趁年少 2024-10-27 01:28:00

设置 alpha 而不是隐藏属性的优点之一是 alpha 属性可以更好地处理动画。我有一个动画来显示/隐藏我的导航栏,当我使用 alpha 属性时,导航栏逐渐消失,而隐藏属性则更加突然。

One advantage of setting alpha instead of the hidden property is that the alpha property plays more nicely with animations. I had an animation to show/hide my navigation bar and when I used the alpha property the navigation bar faded away while the hidden property was more abrupt.

缪败 2024-10-27 01:28:00

是的,两者的行为相同

唯一的区别是如果你想用动画隐藏一些东西,比如透明视图。

您可以将其 alpha 设置为 0.5,而不是在 UIView.animate 中使用 spring 将其 aplha 设置为 0。

其余两者的工作原理相同。

Yes, Both will Act Same

Only difference would be if you want to hide some thing with animation like transparent view.

You can set it's alpha to 0.5 than in UIView.animate with spring set it's aplha to 0.

Rest both of them works the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文