限制UIScrollView中的可滚动区域 [英] Limiting the scrollable area in UIScrollView

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

问题描述

我有一个滚动相当大的UIView的UIScrollView。

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中的可滚动区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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