UIScrollView 不会滚动(故事板) [英] UIScrollView won't scroll (Storyboards)

查看:15
本文介绍了UIScrollView 不会滚动(故事板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是故事板的新手;我之前做过一些 Interface Builder 和很多手动 UI 定位.我搜索了这个问题,尝试了其他相关帖子中的解决方案,但无济于事.

I'm new to Storyboards; I've done some Interface Builder before and lots of manual UI positioning. I've searched this issue, tried the solutions found in the other relevant posts, to no avail.

我有一个在 Storyboards 中添加了 UIScrollView 的视图控制器.ScrollView 插座已连接,属性已合成.滚动启用被选中.弹跳已检查.即便如此,也没有迹象表明会发生任何滚动.当我检查 Bounces Vertically 时,我至少可以看到可滚动的内容,但在我释放后它会反弹回来.我发现的框架尺寸设置为 320 和 521.我尝试了不同的高度,但没有任何帮助.(Storyboards 中设置的尺寸应该是多少,以适应新旧手机尺寸?).

I have a view controller with a UIScrollView added in Storyboards. The ScrollView outlet has been connected, the property synthesized. Scrolling Enabled is checked. Bounces is checked. Even then there was no indication that any scrolling would take place. When I checked Bounces Vertically, I could at least see the scrollable content, but it bounces back after I release. The frame size I found set at 320 and 521. I experimented with different heights but nothing helped. (What ought to be the size set in Storyboards that will accommodate the older and newer phone sizes?).

在viewDidLoad中,我添加了

In viewDidLoad, I added

    [scrollView setContentSize:CGSizeMake(320, 1000)];

随后的日志语句确认该值已被接受.但这也无济于事.

A log statement afterwards confirms that this value has been accepted. But it didn't help either.

有人在一篇帖子中建议添加:

Someone in one post suggested adding:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self.scrollView setContentSize:CGSizeMake(320, 808)];
}

这会在控制器加载时导致程序崩溃.

This had the effect of crashing the program when the controller loaded.

任何帮助将不胜感激!

谢谢.

推荐答案

事实证明有两件事是必要的:

Two things turned out to be necessary:

1) 将滚动视图的高度设置为 480.

1) Set height of scrollview to 480.

2) 将约束添加到滚动视图的最底部字段.约束是 Pin >> Bottom Space to Superview.

2) Add constraint to the bottommost field in the scrollview. The constraint was Pin >> Bottom Space to Superview.

这篇关于UIScrollView 不会滚动(故事板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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