我将 UIView 放在我的 iOS 应用程序的滚动视图中,但它不滚动.我究竟做错了什么? [英] I put the UIView inside a scrollview in my iOS app and it does not scroll. What am I doing wrong?

查看:67
本文介绍了我将 UIView 放在我的 iOS 应用程序的滚动视图中,但它不滚动.我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的故事板中,我将 UIScrollView 放在了我的 UIViewController 上.我在里面放了一个 UIView 和一个 UIButton,但是当我运行应用程序时,我无法滚动 UIView.我做错了什么?

In my storyboard I put the UIScrollView on my UIViewController. Inside I put a UIView with a UIButton, but when I run the app I cannot scroll the UIView. What am I doing wrong?

这是层次结构的样子:

和滚动视图的属性:

和视图(比滚动视图更大):

and the view (which has a bigger size than scrollview) :

如何使它可滚动?

推荐答案

从您的图片看来,您正在使用自动布局.因此,要使视图可滚动,您需要为 scrollview 及其子视图设置约束.

From your image it's look like you are using autolayout. So to make view scrollable you need to set the constraints to scrollview and its sub view.

scrollview 的约束:Top、Trailing、Bottom、Leading 和与 superview 等宽

Constraints for scrollview : Top, Trailing, Bottom, Leading and equal width to superview

视图约束(滚动视图内部):顶部、尾部、底部、前导、与超级视图和高度相等的宽度(无论您想设置什么).

Constraints for view(inside scrollview) : Top, Trailing, Bottom, Leading, equal width to superview and height(whatever you want to set).

在提供这些约束后,您的视图将被滚动.

After giving these constraints your view will be scrolled.

这篇关于我将 UIView 放在我的 iOS 应用程序的滚动视图中,但它不滚动.我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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