故事板中的 UIScrollView 不能与 iOS 8 大小类和自动

UIScrollView in Storyboard not working with iOS 8 Size Classes and Autolayout(故事板中的 UIScrollView 不能与 iOS 8 大小类和自动布局一起使用)
本文介绍了故事板中的 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:

  1. 创建的UIScrollView占据任意宽度任意高度VC的大小

  1. 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

创建了一个 UIScrollViewsubView 视图,其宽度与任意宽度任意高度 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 大小类和自动布局一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)