使用导航控制器嵌入时Xcode滚动视图自动布局问题?(Xcode Scroll View Auto Layout Issue when Embedding with Navigation Controller?)

在导航控制器中嵌入scrollview时,我似乎遇到了问题。 所以这里是我采取的步骤,它很容易复制我似乎越来越奇怪的错误。

1.)拖放一个UIViewController

2.)后面跟着一个UIScrollView

向UIScrollView添加约束,在所有方面添加0,取消选中约束到边距。

3.)将另一个视图拖放到UIScrollView中

向UIScrollView添加约束,在所有方面添加0,取消选中约束到边距。 控制从视图拖动滚动视图,使相同的宽度和高度

在以下步骤之后,您将在下列图像中看到该视图不符合我设置的约束条件,出于某种原因,它认为0是从滚动视图顶部起的+64? 不知道我在这里做错了什么,因为它在视觉上非常讨厌。

I seem to be having issues when it comes to embedding a scrollview within a navigation controller. So here are the steps I take, and its really easy to replicate the weird error i seem to be getting.

1.) Drag and drop a UIViewController

2.) Followed by a UIScrollView

add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins.

3.) Drag and drop another View into UIScrollView

add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins. Control drag from view into scroll view, make same width and height

After the following steps you will see in the following images that the view is not following the constraints I set, for some reason it thinks 0 is +64 from the top of scroll view? Not sure what I'm doing wrong here as it is very annoying visually.

最满意答案

在视图控制器的属性检查器中,查找[顶部|底部]栏选项下的调整滚动视图插入和扩展边缘。 在这里输入图像描述

In your view controller's attributes inspector, look for the Adjust Scroll View Insets and Extend Edges Under [Top|Bottom] Bar options. enter image description here

更多推荐