简体   繁体   English

iOS滚动视图,容器视图 - 自动布局问题

[英]iOS Scroll View, Container View - auto layout issue

I'm using storyboards & auto layout. 我正在使用故事板和自动布局。 I have a Container View in a UIScrollView. 我在UIScrollView中有一个Container View。 The Container View allows me to layout a long (320, 1000) view in the storyboard. 容器视图允许我在故事板中布局长(320,1000)视图。 I set the content size of the UIScrollView to (320,1000). 我将UIScrollView的内容大小设置为(320,1000)。
I pinned the following constraints on the ContainerView to the ScrollView: 我将以下对ContainerView的约束固定到ScrollView:
Width Equals: 320 宽度等于:320
Height Equals: 1,000 高度等于:1,000
Top Space to: Superview 顶级空间:Superview
Align Center X to: Superview 将中心X对齐:Superview

Xcode insists on adding an additional Constraint. Xcode坚持要添加一个额外的约束。 It adds a Bottom Space to: Superview Equals: -432 . 它增加了一个底部空间: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. 在我的iPhone 5和模拟器的4英寸屏幕上一切正常。
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. 当我在Simulator和我的iPhone4S的3.5英寸屏幕上测试它时出现问题。滚动内容大小限制为(320,568),丢失了我的ContainerView的底部部分。

Can someone help me understand why this doesn't work on the 3.5" screens? 有人可以帮助我理解为什么这不适用于3.5英寸屏幕?

Received the answer from Apple Tech support. 收到Apple Tech支持的答复。 It still gives me an error in Xcode, but it functions on 3.5" screens now. Here's the answer: 它仍然在Xcode中给我一个错误,但它现在在3.5“屏幕上运行。 这是答案:

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]. 我不确定为什么界面构建器决定将容器视图的底部与滚动视图的内容视图底部减去432相关联。您无法删除此约束,因为布局必须完全定义[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: 在Interface Builder中:
1) Select the Container View 1)选择容器视图
2) Switch to the Size inspector 2)切换到尺寸检查器
3) Click the gear icon next to the "Bottom Space to: Superview; Equals: -432.0" constraint. 3)单击“Bottom Space to:Superview; Equals:-432.0”约束旁边的齿轮图标。
4) Choose Select and Edit from the menu. 4)从菜单中选择选择和编辑。
5) Enter a value of zero in the constant field. 5)在常量字段中输入零值。

[1]: See the In Depth Explanation section of Technical Note 2154 for more information. [1]:有关详细信息,请参阅技术说明2154的深度解释部分。 https://developer.apple.com/library/ios/#technotes/tn2154/_index.html#//apple_ref/doc/uid/DTS40013309 https://developer.apple.com/library/ios/#technotes/tn2154/_index.html#//apple_ref/doc/uid/DTS40013309

When you embed a view into a UIScrollView in InterfaceBuilder, then there's a constraint automatically set. 将视图嵌入InterfaceBuilder中的UIScrollView时,会自动设置约束。 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. 要让UIScrollView进入AutoLayout,请查看您的约束。 Find "Vertical Space - Scroll View - View" and set it from "constant" to "auto" - fixed everything for me. 找到“垂直空间 - 滚动视图 - 查看”并将其设置为“常量”到“自动” - 为我修复了一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM