开发者

iPhone - subview stacking slowing down application?

开发者 https://www.devze.com 2023-01-06 09:30 出处:网络
As title says, I\'m wondering if stacking subviews can slow down an iPhone application. For example, I have a UIViewController, which has a view occupying the whole screen. When the user presses a bu

As title says, I'm wondering if stacking subviews can slow down an iPhone application.

For example, I have a UIViewController, which has a view occupying the whole screen. When the user presses a button, I create a second view controller and add its view as a subview of the original VC, making the second view completely hide the first one.

Does the application have some kind of automatic optimization which would be something like "ok, I know what to draw for every pixel of the screen, I stop seeking for subviews" ?

If not, I don't think stacking 2 full-screen views can reall开发者_JAVA百科y slow down the app, but could 3, 4 or more views be problematic if they include many subviews themselves (labels, images)?


Read the View Controller Guide sections on Modal View Controllers and memory management. Prefer to use modal Views instead of subviews when you want to present a new screen temporarily and a UINavigationController for "drill-down" views.


You can always set UIView#hidden = YES on the views not seen. That should prevent redraws.


This is largely dependent of what the subviews contain and what is the total memory load of the app. Memory is very crucial for devices like iPhone and you should never keep the things which you don't require. When you are adding many subviews without releasing any, your memory requirement obviously will increase. This may slow down the app, even may crash the app. Stacking of two may not be a problem, but stacking many is not a very good design.

So the summary is you should always check the memory load of the app through instrument and always properly respond to memory warnings.

0

精彩评论

暂无评论...
验证码 换一张
取 消