uiscrollview 只允许向后滚动
我有一个滚动视图,我只想允许用户向后滚动。他们按下按钮进行选择并向前滚动,这部分起作用了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为后退/前进指的是向上和向下。首先,我会在任何有效滚动发生时保存滚动位置。假设您想让用户无法向上滚动,只能向下滚动。每当他们完成向下滚动时,都会调用 UIScrollViews的scrollViewDidEndDecelerating: 方法。我将为 UIScrollView 设置委托并实现该方法。在该方法中,将滚动视图的 contentOffset 设置为您的变量。接下来,实现委托方法scrollViewDidScroll:并检查与存储的偏移量相比的新偏移量。如果新偏移量的 y 值大于(或小于,取决于您限制用户的方式),则手动将滚动视图的偏移量设置为存储的偏移量。
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. I would set the delegate for the UIScrollView and implement that method. In that method set the contentOffset of the scrollview to your variable. Next, implement the delegate method scrollViewDidScroll: and check the new offset compared to your stored offset. 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.