Let's say I have a full-screen UIView
that overlays the main screen when a button is touched, and then goes away when this overlayed view is touched. This UIView
could either be added and removed from the current view using addSubview:
and removeFromSuperview
, or it could be added when the current view is initialized and then shown and hidden by accessing and setting the hidden
property of the UIView
. Which is generally faster and better for performance (or are they the same)?
I did try add imageView and try loop 1000000 times to hide and show in each loop and add remove in each loop. Result is hide and show take 1s to do 1000000 loop. And add remove take 3s. I do it in simulator :)
I'd bet show and hide will be faster. The other way requires object creation/destruction, and fiddling with subviews.
More importantly, I think show and hide will be simpler, and the fight against complexity is paramount.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With