简体   繁体   English

如何使用约束使Scrolling Freedom View控制器可滚动?

[英]How To make Scrollable our Freedom View controller using constraints?

在此处输入图片说明

Actual image is..... 实际图像是..... 在此处输入图片说明

->View controller

   ->view

     ->ScrollView[[top,bottom,leading,trailing]to its super view]

       ->contentView[[top,bottom,leading,trailing,vertical,horizontal]to its scrollview].

that actual image is for iphone6 ->iphone4s,Any one help me how to do this..... 实际的图像是用于iphone6-> iphone4s的,任何人都可以帮助我如何做.....

When it comes to set constraint with scrollview then little bit extraa effort is required for handling scrolling so that Scrollview + autolayout works. 当使用scrollview设置约束时,需要一点额外的精力来处理滚动,以便Scrollview +自动布局可以工作。 First of All What exactly take place when autolayout is used : When you use the auto layout, your views will resized automatically based on the constraint properties. 首先,当使用自动布局时会发生什么:使用自动布局时,视图将根据约束属性自动调整大小。

But, when you use a UIScrollView with auto layout like a container, the auto layout not works like expected. 但是,当您使用具有自动布局的UIScrollView(如容器)时,自动布局无法按预期工作。 so Here is Very good tutorial g8production which clears this confusion. 所以这是很好的g8production教程,它消除了这种混乱。 Big Thanks goes to g8Production for providing this tutorial. 非常感谢g8Production提供了本教程。

I think you are setting the constraints for content view in wrong way. 我认为您以错误的方式设置了内容视图的约束。 You are trying to set the constraints on contentView that are related to its container(scrollview) which don't know content size of its own. 您试图在contentView上设置与其容器(scrollview)相关的约束,这些约束不知道其自身的内容大小。 It determines its content size from what it contains (in your case contentView,). 它根据包含的内容(在您的情况下为contentView)确定其内容大小。 Both are dependent to each other for their size. 两者的大小相互依赖。 So both are confused. 因此两者都感到困惑。 To solve this you should first set the fixed height and width of contentView and then make outlets of these constraints and update these constraints with the height and width of superview when your view loads. 为了解决这个问题,您应该首先设置contentView的固定高度和宽度,然后输出这些约束,并在加载视图时使用superview的高度和宽度更新这些约束。

add top, bottom , leading and trailing space to your scroll view to view. 在滚动视图中添加顶部,底部,前导和尾随空间以进行查看。 It should be set accordingly, how you you want it to be seen. 应该相应地设置它,如何显示它。 Then set same for content view (image). 然后为内容视图(图像)设置相同。 just addheight and width constraint for your image. 只需为图像添加高度和宽度约束即可。

Misha :) Misha :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM