Xamarin iOS:滚动视图中的自动布局? [英] Xamarin iOS: Auto Layout within scroll view?

查看:80
本文介绍了Xamarin iOS:滚动视图中的自动布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在情节提要上有一个scrollView,在其上添加了上,左,右,下约束,以便根据不同的屏幕尺寸自动调整大小.问题是,如果我在此滚动视图中添加图像视图或任何其他内容,并在此图像视图上放置约束以与滚动视图边界的顶部,左侧,右侧和底部保持一定距离.就是行不通.我想根据目标设备的屏幕尺寸调整所有内容的大小.我该怎么办?

I have a scrollView on my storyboard on which I have added top, left, right, bottom constraints in order for it to resize automatically in accordance with different screen sizes. The problem is that if I add image view or any other stuff within this scroll view and place constraints on this image view to maintain some distance from top, left, right and bottom of the scrollview boundaries. It just doesn't work. I Would like to have everything resized according to the screen size of the target device. How could I do so?

浅灰色区域是我的滚动视图,灰色区域是纯视图,最里面的元素是imageview.

Light Grey area is my scrollview, grey area is plain view, innermost element is imageview.

推荐答案

解释起来有点复杂.

我们知道,在autolayout开始工作之前,应该对它们设置约束,根据编译器可以确定控件上的Frame(位置和大小)的约束.

As we know , before the autolayout get working, we should set constraints on them , according to those constraints the compiler can determine the Frame (position and size) on controls.

但是,UIScrollViewUIView有点不同.通常,我们只需要设置left,right,top,bottom,但是在UIScrollView中,它具有一个名为 contentSize 的定义,该定义确定滚动视图的实际大小.因此我们上面设置的约束条件还不够.

However, UIScrollView is a bit of different from UIView. In general, we just need to set left,right,top,bottom , but in UIScrollView, it has a definition called contentSize which determines the actual size of scrollview. so the constraints we set above is not enough.

因此,作为一种解决方法,我们在滚动视图内添加一个容器视图以确定contentSize.

So, as a workaround ,we add a container view inside the scrollview to determine contentSize.

注意:我们设置了额外的宽度(等于scrollview)以表明宽度是固定的,这意味着我们不能水平滚动但允许垂直方向.

pay attention: we set additional width (equal to scrollview) in order to indicate the the width is fixed , means we can't scroll horizontally but vertical orientation is allowed.

这篇关于Xamarin iOS:滚动视图中的自动布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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