What is best for the device when temporarily hiding a view (eg until loading is done)?
Which is best in terms of memory and which is best in terms of performance? I know Apple somewhere wrote something about this, but I can't find it.
Which is best in terms of memory
removeFromSuperview
is the best in term of memory. Why ? Because it will cause the view to be released. So if the view is not retained by anyone else (like a strong ivar), it will be deallocated.
And which is best in terms of performance?
setHidden:
is the best in terms of performance. Why ? Because the action is just to set a flag. And then in drawRect it's just a BOOL check. So it's really fast because there is no other action involved.
So, the fastest method first:
setHidden
(discard view from rendering only) alpha
to 0
is Equal to setHidden, but it first checks if
0` removeFromSuperView
(need some steps: deallocate object, pop from stack (pointer), remove from rendering stack...) frame.origin.y=-10000
> must move a whole bit array and check if the view comes out of bounds. not very fast...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.