Highlighting and sizing pivots in a UIViewController

I have an application with a UITabController , and each tab is a UINavigationController . The root of one of my UINavigationControllers is the UIViewController .

Inside this kind of controller controller, I want to break down some subspecies objects, but I'm confused as to where and how to lay them out in such a way that it will be resolution independent (i.e. not hardcode values ​​like 320px, 480px, 44px, etc.) .d.).

When the view is fully loaded and presented on a vertical iPhone, the height will be 367px = 480 - 20 (status bar) - 44 (navigation bar) - 49 (tab bar).

Inside the view controller, I am currently creating all of my routines in the viewDidLoad method. However, it seems that in this method the height of the current view is 460 pixels ( self.view.bounds.size.height ). Therefore, when setting up my routines, I cannot correctly calculate the size of anything.

In the viewWillAppear: method viewWillAppear: view knows its proper size, but that would mean setting up and calculating subview frames every time a view appears (for example, changing tabs or jumping out of a child view of controllers in the navigation stack.

This is the only way to do it right for the layout in viewWillAppear: :?

I tried using the autoresizesSubviews - autoresizingMask properties (parent autoresizesSubviews and autoresizingMask ), but they don't work at all !? Do they take effect only after all settings are configured and then changed (manual change / orientation?).

I would appreciate it if someone could tell me why automation does not work, and how best to lay out things due to the lack of hard coding of any size.

+47
iphone cocoa-touch uikit uiview
Jan 10
source share
2 answers

autoresizesSubviews should be installed in your parent view, and autoresizingMask should be installed on child views - this is a mistake I made so that you too.

In loadView you should adjust the size of your subzones to fit any size of the parent view, and then when the size of the parent view is changed from 460 to 367 pixels, your subviews will also be resized, according to your mask settings above.

If this fails, there is nothing wrong with adjusting the size of the view in viewWillAppear - the performance impact on it is negligible every time.

If nothing works, there is always layoutSubviews: - there you can do the layout manually, if necessary, it is called when the system believes that the layout can change. there is also setNeedsLayout : sometimes I call from viewWillRotate: / viewDidRotate : etc. But in fact, this is not necessary, and authorization should be good enough.

EDIT: Yes, to implement custom layout logic in layoutSubviews , as I mentioned above, you would need to subclass UIView .

+32
Jan 11 '10 at 6:31
source share

You can execute your layout logic inside viewWillLayoutSubviews UIViewController .

 -(void)viewWillLayoutSubviews{ [super viewWillLayoutSubviews]; // Your layout logic here } 

DOC: Called immediately before the view manager's view. The layoutSubviews method is called. Subclasses can be implemented as needed. The default is nop.

+39
Apr 30 '14 at 16:24
source share



All Articles