iOS Scroll View, Container View - auto layout issue

荒凉一梦 提交于 2019-12-22 08:49:45

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/17073343/ios-scroll-view-container-view-auto-layout-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!