view.alpha = 0 与 view.hidden = YES 有什么影响?
透明度是邪恶的,在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定是否仍绘制 alpha 0.0 的视图。检查文档库:
我也在这里找到了这个答案 http://www.iphonedevsdk.com/forum/iphone-sdk-development/65525-whats-difference- Between-alpha-0-hidden-yes.html
这表示:
I am not sure that a view with alpha 0.0 is still drawn. Check the documentation library:
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:
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.
设置 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.
是的,两者的行为相同
唯一的区别是如果你想用动画隐藏一些东西,比如透明视图。
您可以将其 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.