xcode UIScrollView 不会滚动(故事板)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19458073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:07:33  来源:igfitidea点击:

UIScrollView won't scroll (Storyboards)

iosxcodeuiscrollviewios7

提问by Casey Perkins

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 的新手;我之前做过一些 Interface Builder 和很多手动 UI 定位。我搜索了这个问题,尝试了其他相关帖子中找到的解决方案,但无济于事。

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?).

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

In viewDidLoad, I added

在 viewDidLoad 中,我添加了

    [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.

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

Any help would be greatly appreciated!

任何帮助将不胜感激!

Thanks.

谢谢。

回答by Casey Perkins

Two things turned out to be necessary:

结果证明有两件事是必要的:

1) Set height of scrollview to 480.

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

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

2)向滚动视图中的最底部字段添加约束。约束是 Pin >> Bottom Space to Superview。

回答by Evana

Just add the following method:

只需添加以下方法:

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

This is working perfectly for me.

这对我来说非常有效。