UIScrollView,到达滚动视图的底部
我知道Apple文档有以下委托方法:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt
但是,这并不一定意味着您处于底层。因为如果你用手指滚动一点,然后它会减速,但你实际上并不在滚动视图的底部,那么它仍然会被调用。我基本上想要一个箭头来显示我的滚动视图中有更多数据,然后当您位于底部时(就像它弹跳时)消失。谢谢。
I know the Apple documentation has the following delegate method:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt
However, it doesn't necessarily mean you are at the bottom. Cause if you use your finger, scroll a bit, then it decelerates, but you are not actually at the bottom of your scroll view, then it still gets called. I basically want an arrow to show that there is more data in my scroll view, and then disappear when you are at the bottom (like when it bounces). Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为您可以做的是检查您的
contentOffset
点是否位于contentSize
的底部。因此,您可能会这样做:您可能还需要一个负面案例,以便在用户向上滚动时显示您的指示器。您可能还想添加一些填充,例如,当用户靠近底部但不完全位于底部时,您可以隐藏指示器。
I think what you might be able to do is to check that your
contentOffset
point is at the bottom ofcontentSize
. So you could probably do something like:You'll likely also need a negative case there to show your indicator when the user scrolls back up. You might also want to add some padding to that so, for example, you could hide the indicator when the user is near the bottom, but not exactly at the bottom.
因此,如果您想要快速完成,请执行以下操作:
So if you want it in swift, here you go:
我认为 @bensnider 的答案是正确的,但不是 exart。由于这两个原因,
如果我们检查
if (bottomEdge >=scrollView.contentSize.height)
2 , 该方法将连续调用。在此,如果我们选择
==
检查此条件将有效两次。很少有情况这个条件也有效两次。但用户不会遇到这种情况。
I Think @bensnider answer is correct, But not exart. Because of these two reasons
This method will call continuously if we check for
if (bottomEdge >= scrollView.contentSize.height)
2 . In this if we go for
==
check also this condition will valid for two times.Very few cases this codition is valid for two times also. But User will not come across this.
仅当底部
contentInset
值非负时,接受的答案才有效。稍微的演变将考虑contentInset
的底部,无论其符号如何:The accepted answer works only if the bottom
contentInset
value is non-negative. A slight evolution would consider the bottom of thecontentInset
regardless of it's sign:实际上,这段代码(用 Swift 3 编写)在性能方面不只是将 @bensnider 的代码放入 scrollViewDidScroll 中:
Actually, rather than just putting @bensnider's code in scrollViewDidScroll, this code (written in Swift 3) would be better performance-wise:
它在 Swift 3 中工作:
It work in
Swift 3
:使用诸如
indexPathsForVisibleRows
之类的内容查看 UIView 中当前显示的项目,如果您的模型包含的项目多于显示的项目,请在底部放置一个箭头。See what items are currently displayed in the UIView, using something like
indexPathsForVisibleRows
and if your model has more items than displayed, put an arrow at the bottom.