检查 UIScrollView 是否到达顶部或底部
有没有办法知道 UIScrollView 是否到达顶部或底部?可能在方法中:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate
Is there a way to know if a UIScrollView
has reached the top or bottom? Possibly in the method:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在您的类中实现
UIScrollViewDelegate
,然后添加以下内容:希望这就是您想要的!另外,还可以通过向上面的代码添加更多条件并 NSLog 记录scrollOffset 的值来进行修补。
Implement the
UIScrollViewDelegate
in your class, and then add this:Hope this is what you are after! Else have a tinker by adding more conditions to the above code and NSLog the value of scrollOffset.
好吧,当您尝试确定scrollView是在顶部还是在底部时,也涉及到contentInsets。您可能还对滚动视图位于顶部上方和底部下方的情况感兴趣。
这是我用来查找顶部和底部位置的代码:
Swift:
Objective-C:
Well,
contentInsets
are also involved, when you try to determine whether scrollView is at the top or at the bottom. You might also be interested in cases when your scrollView is above the top and below the bottom.Here is the code I use to find top and bottom positions:
Swift:
Objective-C:
如果你想要快速的代码:
If you want the code in swift:
简单干净的扩展:
在 GitHub 上:
https://github.com/salutis/swift-scroll -视图边缘
Simple and clean extension:
On GitHub:
https://github.com/salutis/swift-scroll-view-edges
我确切地知道了该怎么做:
I figured out exactly how to do it:
这样做(对于 Swift 3):
Do it like this(for Swift 3):