调整的UIView里面的UIScrollView与自动版式滚动? [英] Resize UIView inside UIScrollView with AutoLayout for scrolling?

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

问题描述

我有一个布局如下(使用自动版式,新iPad):

I have a layout as follows(Using AutoLayout,iPad):

的UIScrollView 的顶部,底部,前导,尾随空间到上海华为0。的UIView 也有所有四个类似的限制。第二个的UILabel 有其高度设置为0编程(因为此处显示的文字超过一屏)。此外,这四个引脚约束也已经从的UIView 设置为的UIScrollView

The UIScrollView has Top,Bottom,Leading,Trailing space to the superview as 0. The UIView also has all four similar constraints. The second UILabel has its height set to 0 programmatically (since more than a screenful of text is shown here). Also, these four pin constraints have also been set up from the UIView to UIScrollView.

当XIB被加载,这个的UILabel 正确地显示文字的长行。但滚动不起作用。这是在iPad上运行的应用程序的截图:

When the XIB is loaded, this UILabel shows long lines of text correctly. But scrolling does not work. This is a screenshot of the running app on an iPad:

黄色的背景设置为最外层视图和灰色的为的UIView 。如果你在截图的最后仔细看时,的UILabel 的文字似乎溢出过去的UIView

The yellow background is set for the outermost view and the grey one for the UIView. If you see carefully at the end of the screenshot, the UILabel's text seems to overflow past the UIView.

我怀疑是因为的UIView 不能捕获它的大小是子视图中,的UIScrollView 无法计算它的contentsize太(没有理由如果它的内容视图仅相当于一个屏幕滚动条工作)。这究竟是为什么即使在的UILabel 显然是一个子视图的的UIView ?如果我的怀疑是正确的,如何设置的UIView 的高度等于实际内容的大小,使我的的UILabel 正确的为载?

I suspect that because the UIView cannot "capture" the size of it's subviews, the UIScrollView cannot calculate it's contentsize too(there's no reason for the scrollbar to work if its content view is only equal to one screen). Why is this happening even when the UILabel is clearly a subview of the UIView? If my suspicions are right, how do I set the UIView's height equal to the actual content size so that my UILabel is properly "contained" in it?

(设置的UIView 的高度,宽度静态不是一个选项)。

(Setting the UIView's height,width statically is not an option) .

注:测试XIB而不的UIView 键,只有一个的UILabel (长文本)在的UIScrollView 。现在,滚动作品(因为,我presume,滚动视图可以计算其内容的大小)。

NB: Tested the XIB without the UIView and only a single UILabel (with long text) inside a UIScrollView. Now scrolling works(since, I presume, the scroll view can calculate its content size).

NB2:我也试过在这太问题和这个帖子但我的的UIView 简单地不会超出屏幕的尺寸。 (我只在乎横向滚动)

NB2: I also tried the answers in this SO question and this post but my UIView simply wont extend beyond the dimensions of the screen. (I only care about horizontal scrolling)

推荐答案

自动版式问题是很难用文字来解释。我有同样的问题。我发现这段视频的解决方案。希望这将帮助你。

AutoLayout issues are very hard to explain with text. I was having the same problem. I found the solution in this video. hope this will help you too.

<一个href=\"https://www.youtube.com/watch?v=UnQsFlMGDsI\">https://www.youtube.com/watch?v=UnQsFlMGDsI

此视频演示了如何创建有一些一个UIScrollView
  在屏幕的顶部和在屏幕的底部的视图次
  在自动布局。的UIScrollView内容大小自动调整为
  屏幕或以这样的方式的内容的尺寸大小,该大小
  在较小的设备滚动活跃,对大型设备滚动
  因为它不需要是不活动的。下面的UIButton UITextFields
  始终保持在屏幕的底部,一切工作在所有
  iPhone分辨率(iPhone 4/5/6月6日加)。

This video demonstrates how to create a UIScrollView which has some views on the top of the screen and a view on the bottom of the screen in Autolayout. UIScrollView content size is automatically adjusted to the size of the screen or to the size of the content in such way that on smaller devices scrolling is active and on larger devices scrolling is not active because it is not needed. UIButton below UITextFields always stays on the bottom of the screen and everything works on all iPhone resolutions (iPhone 4 / 5 / 6 / 6 Plus).

这篇关于调整的UIView里面的UIScrollView与自动版式滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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