简体   繁体   English

UIView在UIScrollview中不移动

[英]UIView doesn't move in UIScrollview

I am investigating this problem for three days without much result. 我正在调查此问题三天,但收效不大。

According to what I found on Stackoverflow, I should set the content size bigger than my actual content, which I have done: 根据我在Stackoverflow上发现的信息,我应该将内容大小设置为大于实际内容,这是我完成的:

self.scrollView.contentSize =CGSizeMake(320, 700);

I also have added Autolayout constraints for each item in the scrollview container, to stick to the superview (scrollview) and to each other. 我还为scrollview容器中的每个项目添加了自动布局constraints ,以坚持使用超级视图(scrollview)并相互依赖。

However there is no joy. 但是没有喜悦。 I have uploaded this example on Github. 我已经在Github上上传了这个例子

What am I missing please? 我想念什么? Thanks 谢谢

You have a constraint wrong. 您的约束有误。

在此处输入图片说明

That bottom constraint should be set to 0 (it's -138). 该底部约束应设置为0(为-138)。 Then all should work. 然后所有应该工作。 I just tried it. 我刚试过

If you are using Autolayouts, the contentSize property of UIScrollView doesn't work anymore. 如果您使用的是自动布局,则UIScrollViewcontentSize属性不再起作用。 You will have to establish scrollview intrinsic size using Autolayout constraints. 您将必须使用Autolayout约束来建立scrollview内部尺寸。

You could check this tutorial about ScrollViews and Autolayouts for more info: 您可以查看有关ScrollViews和Autolayouts的本教程,以了解更多信息:

http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/ http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/

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

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