简体   繁体   English

uiscrollview仅允许向后滚动

[英]uiscrollview only allow scrolling back

I have a scroll view that I would like to only allow the user to scroll back. 我有一个只允许用户向后滚动的滚动视图。 They press a button to make a selection and that scrolls forward, this part works. 他们按下按钮进行选择,然后向前滚动,该部分起作用。

I assume back/forward refers to up and down. 我假设后退/前进是指上下。 First, I'd save the scroll position any time a valid scroll occurs. 首先,只要有效滚动就会保存滚动位置。 So say you want to make it so the user cannot scroll up, only down. 假设您要创建它,以便用户不能向上滚动,只能向下滚动。 Whenever they finish scrolling down, the UIScrollViews scrollViewDidEndDecelerating: method will be called. 每当它们完成向下滚动时,将调用UIScrollViews scrollViewDidEndDecelerating:方法。 I would set the delegate for the UIScrollView and implement that method. 我将为UIScrollView设置委托并实现该方法。 In that method set the contentOffset of the scrollview to your variable. 在该方法中,将scrollview的contentOffset设置为您的变量。 Next, implement the delegate method scrollViewDidScroll: and check the new offset compared to your stored offset. 接下来,实现委托方法scrollViewDidScroll:并检查新的偏移量与存储的偏移量之间的比较。 If the y value of the new offset is greater than (or less than, depending on which way you are limiting the user), then manually set the scrollview's offset to the stored offset. 如果新偏移量的y值大于(或小于,取决于您限制用户的方式),则将滚动视图的偏移量手动设置为存储的偏移量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM