限制 UIScrollView 中的可滚动区域

Limiting the scrollable area in UIScrollView(限制 UIScrollView 中的可滚动区域)
本文介绍了限制 UIScrollView 中的可滚动区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 UIScrollView 正在滚动一个相当大的 UIView.

I have a UIScrollView that is scrolling a fairly large UIView.

在某些时候我想限制用户可以滚动的区域.例如,我可能只想让他们查看视图的底部四分之一.

At certain times I want to limit the area the user can scroll around in. For example, I may only want to allow them to view the bottom quarter of the view.

如果视图滚动得太远,我可以通过覆盖 scrollViewDidScroll 然后调用 setContentOffset 来限制区域.但是这样我就不能让它像 UIScrollView 在滚动超出 UIView 的边界时那样平滑地反弹.

I am able to limit the area by overriding scrollViewDidScroll and then calling setContentOffset if the view has scrolled too far. But this way I can't get it bounce back as smoothly as the UIScrollView can naturally do when scrolling beyond the bounds of the UIView.

有没有更好的方法来限制 UIScrollView 中的可滚动区域?

Is there a better way to limit the scrollable area in a UIScrollView?

推荐答案

我会将滚动视图的 contentSize 属性更改为您希望用户能够滚动的区域的大小并调整 frame.origin您想要的子视图的左上边界相对于滚动视图显示在 (0, 0) 处.例如,如果您的视图高度为 800 磅,并且您想显示底部四分之一,请将 contentSize 的高度设置为 200,并将 view.frame.origin 的 y 分量设置为 -600.

I would change the contentSize property of the scroll view to the size of the area you want the user to be able to scroll around in and adjust the frame.origin of the subview such the upper left boundary you want appears at (0, 0) relative to the scroll view. For example, if your view is 800 points tall and you want to show the bottom quarter, set the height of contentSize to 200 and set the y component of view.frame.origin to -600.

这篇关于限制 UIScrollView 中的可滚动区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
How to Cancel Scrolling in UIScrollView(如何在 UIScrollView 中取消滚动)