iOS Scroll View, Container View - auto layout issue
Asked Answered
L

2

4

I'm using storyboards & auto layout. I have a Container View in a UIScrollView. The Container View allows me to layout a long (320, 1000) view in the storyboard. I set the content size of the UIScrollView to (320,1000).
I pinned the following constraints on the ContainerView to the ScrollView:
Width Equals: 320
Height Equals: 1,000
Top Space to: Superview
Align Center X to: Superview

Xcode insists on adding an additional Constraint. It adds a Bottom Space to: Superview Equals: -432. It will not let me delete this constraint! I'm not sure if this affects the issue below.

Everything works fine on the 4" screen of my iPhone 5 and Simulator.
My problem comes when I test it on the 3.5" screen in the Simulator & my iPhone4S. The scrolling content size becomes restricted to (320, 568), losing the bottom section of my ContainerView.

Can someone help me understand why this doesn't work on the 3.5" screens?

Lerma answered 12/6, 2013 at 19:6 Comment(0)
L
12

Received the answer from Apple Tech support. It still gives me an error in Xcode, but it functions on 3.5" screens now. Here's the answer:

I'm not sure why interface builder decided to relate the bottom of the container view to the bottom of the scroll view's content view minus 432. You can not remove this constraint because it is necessary for the layout to be fully defined [1]. However, if you promote that constraint to a user constraint, you can edit the constant value to zero. This will correct the issue where the bottom part of your content was being cutoff.
In Interface Builder:
1) Select the Container View
2) Switch to the Size inspector
3) Click the gear icon next to the "Bottom Space to: Superview; Equals: -432.0" constraint.
4) Choose Select and Edit from the menu.
5) Enter a value of zero in the constant field.

[1]: See the In Depth Explanation section of Technical Note 2154 for more information. https://developer.apple.com/library/ios/#technotes/tn2154/_index.html#//apple_ref/doc/uid/DTS40013309

Lerma answered 20/6, 2013 at 17:54 Comment(1)
Scott's awesome answer doesn't seem to apply to xcode 5, how would I fix this in xcode 5?Diurnal
L
0

When you embed a view into a UIScrollView in InterfaceBuilder, then there's a constraint automatically set. If your view is "longer" than the screen in portrait, it wont scroll at all. But if you rotate the screen, you'll notice the ability to scroll a little. To get UIScrollView going in AutoLayout look into your constraints. Find "Vertical Space - Scroll View - View" and set it from "constant" to "auto" - fixed everything for me.

Laid answered 28/9, 2013 at 10:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.