如何阻止 iOS 应用向上滚动

How to stop iOS app from scrolling up

我使用常见的自动布局和 UIScrollView 教程在滚动视图中创建了一个内容视图添加了约束。但是,当没有内容时,如何阻止我的Scrollview向上滚动,视图向下滑动到内容,但是我想禁用向上滚动,我搜索了答案但是找不到none,请帮助.

略微超出 UIScrollView 内容的能力称为 "bouncing"。

The scroll view must know the size of the content view so it knows when to stop scrolling; by default, it “bounces” back when scrolling exceeds the bounds of the content.

您需要将退回设置为无:

If the value of [bounces] is YES, the scroll view bounces when it encounters a boundary of the content. Bouncing visually indicates that scrolling has reached an edge of the content. If the value is NO, scrolling stops immediately at the content boundary without bouncing. The default value is YES

scrollView.bounces = NO;