的UIScrollView和经销商的布局不工作 [英] UIScrollView and auto layout not working

查看:117
本文介绍了的UIScrollView和经销商的布局不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的应用程序滚动视图。

I'm trying to make a view scrollable in my app.

Ø按照教程 https://www.youtube.com/watch?v完全步骤= UnQsFlMGDsI

主要步骤我做是:


  • 添加一个UIScrollView

  • 添加到视图UIScrollView的(查看内容)

  • 与UIScrollView的值为0(顶部,左侧,右侧和钮)创建保证金的限制

  • 与内容视图值0(顶部,左侧,右侧和钮)创建保证金的限制

  • 创建相等宽度和高度平等内容查看和主视图
  • 之间的2约束
  • ...(添加一些文本字段)

  • Add a UIscrollView
  • Add a view into UIscrollView (Content View)
  • Create the margin constraints with value 0 (top, left, right and botton) for UIScrollView
  • Create the margin constraints with value 0 (top, left, right and botton) for Content view
  • Create 2 constraints of "equal width" and "equal height" between ContentView and main view
  • ... (Add some text fields)

当我运行应用程序时,滚动视图无法正常工作

When I run the app, the scrollView doesn't work

在这里输入的形象描述

我真的不能使它发挥作用。我试了很多办法申请一个UIScrollView并没有得到它。

I really can't make it work. I tried many ways to apply a UIScrollView and didn't get it.

推荐答案

由于在视频中提到的,主要目的是自动调整的UIScrollView contentSize 来在屏幕的大小或以这样的方式的内容,在较小的设备的滚动是活性的大小和在较大的设备的滚动,因为它不需要是不活动的。

As mentioned in the video, the main aim is to automatically adjust the UIScrollView contentSize 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.

有关此实现您所设定适当的约束,从而使高度自动计算的内容视图。从视频看到它你没有设置正确的约束 最后UITextFeild (这很重要)

For this to achieve you've to set proper constraints to the content view so that the height is automatically calculated. From your video its visible that you're not setting the proper constraint to the last UITextFeild (this is important).

您必须给在以及在 约束到最后的UITextField 这样的内容查看高度自动计算。

You have to give the top as well as the bottom constraint to the last UITextField so that contentView height is automatically calculated.

我已经做了一个示例项目,你可以点击这里:结果
示例项目

I have done a sample project which you can check here :
Sample Project

这篇关于的UIScrollView和经销商的布局不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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