Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

speed of UIView add/remove subview versus hiding/showing

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)?

like image 826
Hari Ganesan Avatar asked Feb 24 '14 16:02

Hari Ganesan


2 Answers

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 :)

like image 132
larva Avatar answered Sep 20 '22 12:09

larva


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.

like image 27
Clay Bridges Avatar answered Sep 18 '22 12:09

Clay Bridges