UIScrollView AutoLayout Vertical Only(UIScrollView AutoLayout 仅垂直)
问题描述
我想让 AutoLayout 与 UIScrollView
一起工作,但遇到了一些麻烦.这是我所做的:
在主视图中添加一个
UIScrollView
框架:[top: 0, left: 0, width: 320, height: 568]在
UIScrollView
中添加UIView
"ContentView",带有框架和 bgcolor black: [top: 0, left: 0, width: 320, height: 568]设置
UIScrollView
约束:[top: 0, bottom: 0, left: 0, right: 0]设置ContentView"约束:[top: 0, bottom: 0, left: 0, right: 0]
对齐ContentView"内的项目
将主视图的 bgcolor 设置为灰色(以查看发生了什么)
这是问题的截图:
self.scrollView.directionalLockEnabled = YES;
I want to get the AutoLayout working with the UIScrollView
and am having a little trouble with it. Here is what I did:
Add a
UIScrollView
inside the Main View with frame: [top: 0, left: 0, width: 320, height: 568]Add
UIView
"ContentView" inside theUIScrollView
with frame and bgcolor black: [top: 0, left: 0, width: 320, height: 568]Setup
UIScrollView
constraints: [top: 0, bottom: 0, left: 0, right: 0]Setup "ContentView" constraints: [top: 0, bottom: 0, left: 0, right: 0]
Align the items inside the "ContentView"
Set Main View bgcolor to gray (to see what's going on)
Here is a screenshot of the problem:
1
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 below:
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.
EDIT: I also added ContentView's width and height as constraints and that didn't help either.
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)];
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 AutoLayout 仅垂直的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIScrollView AutoLayout 仅垂直
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01