UIScrollView in Storyboard not working with iOS 8 Size Classes and Autolayout(故事板中的 UIScrollView 不能与 iOS 8 大小类和自动布局一起使用)
问题描述
所以我试图只在情节提要中创建一个 UIScrollView
,它允许我添加超过 VC 高度的滚动标签.这是我所做的:
So I'm trying to create a UIScrollView
only in storyboard that allows me to add scrolling labels for more than the height of the VC. Here's what I did:
创建的
UIScrollView
占据任意宽度任意高度VC的大小
Created
UIScrollView
that took up the size of the any width any height VC
在顶部、底部、左侧和右侧设置了与最近邻居的间距为 0
Made constraints 0 for spacing to nearest neighbor on top, bottom, left, and right
创建了一个 UIScrollView
的 subView
视图,其宽度与任意宽度任意高度 VC 相同,但高度为 1500(因为我只想要它垂直滚动).
Created a view that is a subView
of the UIScrollView
with the same width as the any width any height VC but height of 1500 (because I only want it to scroll vertically).
将最近邻的约束设置为 0,仅用于左侧、顶部和右侧,并将高度约束设置为 1500.
Set constraints to nearest neighbor as 0 for ONLY left, top, and right and set the height constraint as 1500.
我在subView
的顶部和底部放了一个标签
I put a label at the top of the subView
and at the bottom
当我在 iPhone 6 上运行该应用程序时,不会像我想要的那样垂直滚动.任何想法为什么这不起作用?提前致谢.
When I run the app on an iPhone 6, does not scroll vertically as I want it to. Any ideas why this is not working? Thanks in advance.
推荐答案
要获得滚动,您必须将子视图(内容视图")固定到滚动视图的顶部、左侧、底部和右侧.此外,您必须给它(给内容视图")一个明确的(=与滚动视图无关)高度和宽度,因为滚动视图使用这些来计算其内容大小.在您的情况下,将宽度设置为 VC 主视图宽度,将高度设置为 1500.当宽度或高度大于滚动视图大小时,它将滚动.
To obtain the scroll you have to pin the sub view (the "content view") to the top, left, bottom and right of the scrollview. In addition you have to give it (to the "content view") an explicit (=not related to the scroll view) height and width because these are used by the scrollview to calculate its content size. In your case set the width equal to the VC main view width and the height to 1500. When width or height are bigger than the scrollview size, it will scroll.
滚动视图约束(固定到主视图)
Scroll view constraints (pinned to main view)
内容视图(固定到滚动视图 + 高度 1500,宽度=主视图宽度)+ 标签约束(例如:内容视图左上角 20 20)
Content view (pinned to scrollview + height 1500, width=mainview width) + label constraints (as an example: 20 20 from content view top left)
这篇关于故事板中的 UIScrollView 不能与 iOS 8 大小类和自动布局一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:故事板中的 UIScrollView 不能与 iOS 8 大小类和自动
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01