Xcode ScrollView 不滚动 [英] Xcode ScrollView doesn't scroll

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

问题描述

我正在尝试使用最新的 xcode 实现滚动视图.

I'm trying to implement scrollview using latest xcode.

我的内容达到越界",当我运行模拟器时,我无法向下滚动以查看其余内容.

I have content that reaches 'out of bounds' and when I run the simulator, I'm unable to scroll down to see the rest of my content.

我的层次结构/约束如下..

My hierarchy / constraints are as follows..

您是否需要对contentView"中的子视图进行限制?我的视图控制器中没有额外的代码来操作滚动视图.

Are there constraints you need to have on the subviews within the 'contentViiew' ? I don't have additional code in my view controller that manipulates the scrollview.

使用 Xcode -v 11 &Swift -v 5 <- 如果这有区别

using Xcode -v 11 & Swift -v 5 <- if this makes a difference

推荐答案

请清除 contentView 上的所有约束,然后进行如下操作.垂直滚动的 scrollView 需要以下约束:

Please clear all constraints on contentView and proceed as follows. You need the following constraints for a vertically scrolling scrollView:

1) 将您的 ContentView 限制为与 scrollView 的各个边的距离为零.

1) Constraint your ContentView to have zero distance from all over sides of scrollView.

2) 对 scrollView 等高宽约束.具有较低优先级的高度约束(比如 400).

2) Equal height and width constraint to scrollView. The height constraint to have lower priority (say 400).

子视图的唯一约束是它们都有相对于它们上方的视图设置的约束.此外,底部子视图应该有一个底部约束,以便 scrollView 滚动.

The only constraint for subviews is that they all have constraints set relative to view just above them. Also, the bottom subview should have a bottom constraint for scrollView to scroll.

我的意思是所有的 UIViews 都应该有相对的垂直约束.例如,如果从上到下,您有三个视图 - A->B->C,则需要以下约束-1) 顶到 A2) A 到 B3) B 到 C最重要的是4) C 到底部.如果您在界面构建器中遇到错误,您可以使用>="代替="#4 的约束.我希望这会有所帮助.

What I mean by this is that all UIViews should have relative vertical constraints. for example, if going from top to bottom, you have three views - A->B->C, then following constraints are required - 1) top to A 2) A to B 3) B to C and most importantly 4) C to bottom. If you get an error in interface builder, you can use ">=" instead of "=" constraint for the #4. I hope that helps.

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

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