Question

I can't figure out how to correctly position subviews in a Navigation Controller. I am trying to position a view, table and another view.

enter image description here

If I turn off AutoLayout than top view and table are ok but my bottom view is pushed off the screen. With autolayout I get both the table and bottom view in the wrong place:

enter image description here

I try to set frame in viewDidLoad as follows (calendarPicker is position at the top below navigation bar), I want the configPanel to be on the bottom, I hide bottom bar on Push.

self.eventsTable.frame = CGRectMake(0, CGRectGetMaxY(self.calendarPicker.frame),
                                    self.eventsTable.bounds.size.width,
                                    self.view.bounds.size.height - self.calendarPicker.bounds.size.height
                                    );
self.configPanel.frame = CGRectMake(0, self.view.bounds.size.height,
                                    self.configPanel.bounds.size.width,
                                    self.view.bounds.size.height - self.configPanel.bounds.size.height
                                    );

Should I rely on autolayout? How should I make my constraints? I believe my problems arise due to autosizing of the table mostly, but given that I am setting its frame size why would it not change? I do not want to remove auto layout since it is used on other views designed in the storyboard and from what I understand it applies to all? Is there something that I am missing that needs to be done on top of setting the frames of individual controls?

EDIT: I think my biggest problem is autolayout and inability to size table appropriately. If I add constraint to the bottom view to be 0 from bottom of the view, it will originally appear correctly. However consequently when resizing table and top view, the table will push bottom view down sizing itself to occupy all available space. I need to force UITableView to be no more than height between the bottom of the top view and lower view, but still not sure how to do this. Somewhat closer Removing code for frame change of the table fixes the issue of the bottom view being pushed off. However in this case top view overlapps table when it changes size at the same time not being drawn correctly: enter image description here

Was it helpful?

Solution

Uncheck autolayout and then set frames of all three subviews. Or If you want constraints then you can use NSLayoutConstraint class to add constraint to your subviews.

OTHER TIPS

I recommend against switching off autolayout, especially because you can't do it on a view by view basis. Autolayout is a must if you tend to do i18n or want to make sure your app does well in different screen resolutions/orientation.

Try This! disable use Autolayout in storyboard. Place your three views on view controller(view1, view2, view3). Next go to size inspector and use autosizing masks for all three views. Check this, which will help you http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top