简体   繁体   English

尽管我添加了适当的约束,但Scrollview没有使用自动布局滚动

[英]Scrollview is not scrolling using autolayout though I have added proper constraints

I have got a layout in following form 我有以下格式的布局

I have got the views in following hierarchies. 我对以下层次结构有意见。

  ---View
    -------TopView
    ---------Label
  --Scrollview
  ---------ContentView
  ----Buton

The content view has got the constraing attributes as in the following picture, 内容视图具有令人信服的属性,如下图所示,

在此处输入图片说明

The problem is that scrollview is not getting scrolled. 问题是scrollview没有滚动。 Am i missing any layout constraints from being set? 我是否错过了设置的布局限制? scroll view is of width 374 and height 534. Contentview is of width 334 and height 494 滚动视图的宽度为374,高度为534。Contentview的宽度为334,高度为494

Every time you try to add the scroll view on something like submit application/ form then remember these steps: 每次您尝试在诸如提交申请/表格之类的内容上添加滚动视图时,请记住以下步骤:

  1. On base view add a scroll view with frame exactly equal to base view 在基础视图上添加滚动视图,其框架与基础视图完全相同

  2. add top left bottom and right constrain (should be 0 each) 添加顶部,左侧,底部和右侧约束(每个应为0)

  3. take another view with equal frame to scroll view and set 0 constrain to default four constraint type ie TOP Bottom trailing leading. 采取另一个具有相等框架的视图滚动视图,并将0约束设置为默认的四个约束类型,即“顶部底部拖尾”。
  4. Also give equal height and width to base view constraint. 还给基本视图约束相等的高度和宽度。
  5. Now try to add a button just above bottom on 2nd view 现在尝试在第二个视图的底部上方添加一个按钮
  6. give following 给以下
    constrain to button : Horizontally center, width , height , 限制按钮:水平居中,宽度,高度,
    bottom. 底部。
  7. Try to run on simulator You should be able to scroll till button. 尝试在模拟器上运行您应该能够滚动到按钮。

Have you set ScrollView contentSize ? 您设置了ScrollView contentSize吗?
Please check you have set scrollable height. 请检查您是否设置了可滚动的高度。

Eg. 例如。

 scrlVIewSignUp.contentSize = CGSizeMake(self.view.frame.width, 1000)  

Where 1000 is the approximate height.(please set height as per your requirement) 大约高度为1000(请根据您的要求设置高度)

I assume you are running into issues with the contentSize. 我假设您遇到了contentSize问题。 Check out this .it is about how to handle the contentSize when using a "pure" AutoLayout approach. 看看这个 .it关于使用“纯”自动布局方法时如何处理contentSize。 The gist of it is that your constraints implicitly define the content size. 其要点是您的约束隐式定义了内容大小。 You NEVER set it explicitly when using AutoLayout. 使用AutoLayout时,您永远不要显式设置它。

it also have, attached example project at the end of the blog post to demonstrate how it works. 它还在博客文章的末尾附加了示例项目,以演示其工作原理。

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

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