Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

ios - What is the impact of view.alpha = 0 vs view.hidden = YES?

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.

question from:https://stackoverflow.com/questions/5146947/what-is-the-impact-of-view-alpha-0-vs-view-hidden-yes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...