自动版式的UIScrollView只有垂直 [英] UIScrollView AutoLayout Vertical Only

查看:126
本文介绍了自动版式的UIScrollView只有垂直的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要得到的自动版式与的UIScrollView 工作,我用起来有点麻烦了。下面是我所做的:

I want to get the AutoLayout working with the UIScrollView and am having a little trouble with it. Here is what I did:


  1. 添加的UIScrollView 主视图与框架内:[顶:0,左:0,宽度:320,高度:568]

  1. Add a UIScrollView inside the Main View with frame: [top: 0, left: 0, width: 320, height: 568]

添加的UIView 内容查看中的的UIScrollView 与框架和的bgcolor黑色:[顶:0左:0,宽度:320,高度:568]

Add UIView "ContentView" inside the UIScrollView with frame and bgcolor black: [top: 0, left: 0, width: 320, height: 568]

设置的UIScrollView 约束:[顶:0,底部:0,左:0,右:0]

Setup UIScrollView constraints: [top: 0, bottom: 0, left: 0, right: 0]

设置内容查看约束:[顶:0,底部:0,左:0,右:0]

Setup "ContentView" constraints: [top: 0, bottom: 0, left: 0, right: 0]

对齐里面的内容查看

设置主视图的bgcolor为灰色(看看是怎么回事)

Set Main View bgcolor to gray (to see what's going on)

这是问题的截图: http://imgur.com/P8s9lB0

有关某些原因,限制使内容视图是在屏幕的中间。此外,它滚动在每一个方向。我想内容要滚动只在像的UITableView 垂直方向,使我不能移动它像:的 http://imgur.com/lBCwfAS

For some reason, the constraints make the content view be in the middle of the screen. Also, it scrolls in every direction. I want the content to be scrollable only in vertical direction like in UITableView, so that I can't move it like that: http://imgur.com/lBCwfAS

我是什么做错了吗?我检查了所有的教程和答案,我可以在计算器和谷歌发现,没有人居然有只一个奇怪的问题,所以我寻求帮助。

What am I doing wrong? I have checked all the tutorials and answers I can find in StackOverflow and Google, and no one actually has just a bizarre problem, so I am asking for help.

编辑:我还添加了内容查看的宽度和高度的限制,但这并没有帮助

I also added ContentView's width and height as constraints and that didn't help either.

推荐答案

有关禁用水平滚动,你可以在(无效)scrollViewDidScroll方法设置的内容大小。

For disabling the horizontal scroll, you can set the content size in the (void)scrollViewDidScroll method.

[self.scrollView setContentOffset: CGPointMake(0, self.scrollView.contentOffset.y)];

您还需要设置定向锁定所以只有1滚动方向在同一时间使用。 <一href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollView_Class/index.html#//apple_ref/occ/instp/UIScrollView/directionalLockEnabled\">https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollView_Class/index.html#//apple_ref/occ/instp/UIScrollView/directionalLockEnabled

You'll also want to set the directional lock so only 1 scroll direction is used at a time. https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollView_Class/index.html#//apple_ref/occ/instp/UIScrollView/directionalLockEnabled

self.scrollView.directionalLockEnabled = YES;

这篇关于自动版式的UIScrollView只有垂直的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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