Cry*_*tal 37 iphone uiscrollviewdelegate
我知道Apple文档具有以下委托方法:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt
Run Code Online (Sandbox Code Playgroud)
但是,这并不一定意味着你处于最底层.因为如果你使用你的手指,滚动一下,然后它减速,但你实际上并不在滚动视图的底部,然后它仍然被调用.我基本上想要一个箭头来显示我的滚动视图中有更多数据,然后当你在底部时就会消失(就像它反弹时一样).谢谢.
ben*_*der 100
我认为你可以做的是检查你的contentOffset观点是否在底部contentSize.所以你可以这样做:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
if (bottomEdge >= scrollView.contentSize.height) {
// we are at the end
}
}
Run Code Online (Sandbox Code Playgroud)
当用户向上滚动时,您可能还需要一个负面的案例来显示您的指示器.您可能还想添加一些填充,例如,当用户靠近底部时,您可以隐藏指示符,但不能完全隐藏在底部.
ytb*_*yan 17
所以,如果你想要它迅速,那么你去:
override func scrollViewDidScroll(scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
//reach bottom
}
if (scrollView.contentOffset.y < 0){
//reach top
}
if (scrollView.contentOffset.y >= 0 && scrollView.contentOffset.y < (scrollView.contentSize.height - scrollView.frame.size.height)){
//not top and not bottom
}
}
Run Code Online (Sandbox Code Playgroud)
uma*_*nta 14
我认为@bensnider的回答是正确的,但不是exart.因为这两个原因
1. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{}
Run Code Online (Sandbox Code Playgroud)
如果我们检查,这种方法将连续调用 if (bottomEdge >= scrollView.contentSize.height)
2.如果我们去==检查这个条件也会有效两次.
我觉得这更准确.
极少数情况下,这个法典也有效两次.但是用户不会遇到这个.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y == roundf(scrollView.contentSize.height-scrollView.frame.size.height)) {
NSLog(@"we are at the endddd");
//Call your function here...
}
}
Run Code Online (Sandbox Code Playgroud)
只有在底部contentInset值为非负值时,接受的答案才有效.一个轻微的演变将考虑到contentInset它的底部而不管它的标志:
CGFloat bottomInset = scrollView.contentInset.bottom;
CGFloat bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height - bottomInset;
if (bottomEdge == scrollView.contentSize.height) {
// Scroll view is scrolled to bottom
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34366 次 |
| 最近记录: |