I am updating an app to run on the iPhone 5 screen (while maintaining the old screen size layout as well).
I have a xib file that contains a view controller’s main view, with a horizontal scroll view in it as a subview. This scroll view’s height gets stretched vertically on the iPhone 5 screen.
I also have three views in the xib (used as pages in the scroll view) that get added to the scroll view. I have set all the struts and springs for the top most views to on. I have set all the struts and springs for the subviews inside these views to off.
My problem is that the subviews do not get positioned correctly on the iPhone 5 screen. Specifically I have an image view that should be positioned near the top of the view that is getting moved to the bottom (underneath the other subviews, when they should not be overlapping at all). Setting the top strut to on on the image view causes it to stay at the top of the view, but I want it moved down proportionally to the change in view height.
In my view controller’s viewDidLoad I add the pages to the scroll view like this:
_pageOne.frame = CGRectMake(0, 0, _scrollView.bounds.size.width, _scrollView.bounds.size.height);
[_scrollView addSubview:_pageOne];
_pageTwo.frame = CGRectMake(320, 0, _scrollView.bounds.size.width, _scrollView.bounds.size.height);
[_scrollView addSubview:_pageTwo];
_pageThree.frame = CGRectMake(640, 0, _scrollView.bounds.size.width, _scrollView.bounds.size.height);
[_scrollView addSubview:_pageThree];
The views are set up in the xib for the old screen height. I have checked in the debugger that the scroll view has already been stretched in the viewDidLoad.
How can I get my subviews to reposition correctly?
(Moved response to comment to an answer)
I actually solved my issue by setting the top and bottom strut on my image view, turning on the vertical spring, and setting the image view’s contentMode to UIViewContentModeCenter.
But here is how I had my view set up:
And here is the result on the iPhone 5.
I hadn’t realized that my image view was right at the top of my view. I tried moving the image view down a little, and turning off all of the struts and springs, and everything started behaving as expected: