UIScrollView Controller无法完全滚动 [英] UIScrollView Controller not scrolling fully

查看:109
本文介绍了UIScrollView Controller无法完全滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很确定这与可怕的AutoLayout有关. (从2天开始尝试摆脱困境)

所以我有点掌握了它,但是现在我的UIScrollView没有完全向下滚动时出现了问题,图片在解释这些问题上要好得多

这是滚动视图

这是内容视图

所以问题是正在发生滚动,但随后又弹回了.所以我无法点击注册按钮

EDIt 1

解决方案

我在github上创建了一个小示例供您查看,此处.该项目说明了下面的答案,并使用了我所描述的技术,仅此而已.

原始答案:

我在这里建议的几件事.

  1. 首先,我知道您已经尝试了一段时间,但是删除了所有当前的限制(我知道但是很痛苦).这样做是为了清楚起见....

  2. 视图应为场景的大小,看起来您希望滚动视图为全屏,因此也需要为场景的大小.

例如如果您默认在6Plus上进行设计,则场景大小为414x736,因此视图及其包含的滚动视图也应为414x736.

  1. 仅内容视图需要为您希望显示的真实内容的大小.出于参数考虑,我们说内容为414x1000.

现在,滚动视图的约束很简单.它的所有边缘都需要零间距.

您可以通过两种方式将内容视图添加到滚动视图.我尝试执行此操作的方式因项目而异,并且主要取决于场景的复杂程度.如果这是一个非常繁忙的场景,则将内容视图保留在Interface Builder中的滚动视图之外,以便我可以轻松地对其进行处理并可视化整个视图.然后,将内容视图添加到代码中的滚动视图中.

如果视图更简单,则可以在界面生成器的滚动视图中添加它.最终,无论采用哪种方式,您都可能在界面生成器中失去内容视图的可见性,因为contentview大于滚动视图并且内容被遮盖了.因此,尽情玩乐并为您找到一个好方法.

  1. 定义内容视图及其所有子视图.内容视图必须比滚动视图高,否则它将不会滚动.内容视图的所有子视图都需要从上到下定义高度,从左到右定义宽度.在您的情况下,scrollview垂直滚动而不是水平滚动,因此所有宽度都需要累加到滚动视图的宽度,但是高度需要累加到内容视图的整个高度.

注意:如果您按比例进行此操作,以后的生活将会更加轻松.如果您以固定的高度执行所有这些操作,则情节提要板将在不同的设备尺寸上损坏.

  1. 现在是棘手的位",这有点反直观.您需要将内容视图固定到滚动视图,请记住内容视图的高度高于滚动视图.在Interface Builder中的所有其他情况下,将视图固定到超级视图(0填充)将相应地调整高度(或宽度).对于滚动视图与其内容视图之间的关系,不会发生.

首先固定contentview

注意到-400吗?请记住,内容视图比滚动视图高,我们将立即对其进行更改.

选择我们刚刚创建的最低约束(​​-400):

选择常量值旁边的下拉箭头:

选择标准值并输入0作为常数.

您现在应该有一个没有破坏性约束的情节提要,并且如果您要构建和运行它,则应该获得所需的滚动视图.

I am pretty sure this has something to do with the dreaded AutoLayout. (been trying since 2days to get hang of it)

So I mastered it somewhat, but now I have problem where my UIScrollView is not scrolling fully down, pictures are much better at explaining these things

this is the scroll view

this is the content view

so the problem is the scrolling is happening but then again it springs back up. So I am not able to click on the signup button

EDIt 1

解决方案

Edit:

I have created a little example on github for you to look at, here. The project illustrates the answer below and uses the techniques I describe and nothing else.

Original Answer:

couple of things I would advise here.

  1. First, I know you've been trying for a while but remove all the current constraints (painful I know but). Do this for clarity as ....

  2. The view should be the size of the scene, it looks like you want the scrollview to be the full screen so that too needs to be the size of the scene.

e.g. if you are designing at 6Plus by default the scene size is 414x736 so the view and the scrollview it contains should also be 414x736.

  1. Only the content view needs to be the size of the real content you wish to show. Let's say for arguments sake that the content is 414x1000.

Now the constraints for the scrollview are simple. It needs zero spacing to all it's edges.

You can add the content view to the scrollview in a couple of ways. The way I try to do this varies from project to project and depends mostly on how complex the scene is. If it's a really busy scene I keep the content view outside of the scrollview in interface builder so that I can work on it easily and visualize the whole of the view. Then I add the content view to the scrollview in code.

If its a simpler view You can add it inside the scrollview in interface builder. Ultimately whichever way you do it, you can lose visibility of the content view in interface builder because the contentview is larger than the scrollview and the content gets obscured. So play about and find a good way for you.

  1. Define the content view and all it's subviews. The content view needs to be taller than the scrollview otherwise it wont scroll. All of the content view's subviews need to have defined heights from top to bottom and widths from left to right. In your case the scrollview is scrolling vertically not horizontally so all the widths need to add up to the width of the scroll view BUT the heights need to add up to the full height of the content view.

Note: if you do this proportially your life will be easier later. If you do all this with fixed heights the storyboard will break on different device sizes.

  1. Now the "tricky bit" and it's a bit counter intuitive. You need to pin the content view to the scrollview, remember the height of the content view is taller than the scrollview. In all other circumstances in Interface Builder pinning a view to a superview (0 padding) will adjust the height (or width) accordingly. For the relationship between a scrollview and it's content view this doesn't happen.

First pin the contentview

Notice the -400? Remember the content view is taller than the scrollview and we will change this immediately.

Select the bottom constraint (-400) that we have just created:

Select the drop down arrow next to the constant value:

Select Standard Value and type in 0 for the constant.

You should now have a storyboard with no broken constraints and if you build and run you should get a scrollview as desired.

这篇关于UIScrollView Controller无法完全滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆