简体   繁体   English

检测UIScrollview滚动到底

[英]Detect UIScrollview scrolling past bottom

I'm trying to create functionality similar to Reeder where you are introduced to new content if you scroll below or above the content in a scroll view. 我正在尝试创建类似于Reeder的功能,如果您在滚动视图中在内容的下方或上方滚动,则会向您介绍新内容。

I thought I was heading in a good place with scrollViewWillEndDragging:withVelocity:targetContentOffset: 我以为我要通过scrollViewWillEndDragging:withVelocity:targetContentOffset到达一个好的地方:

However, this just stops at the bottom. 但是,这仅停留在底部。

Is there any way to detect if you are scrolling beyond the bottom or top (this is when the vertical scrollbar begins to get smaller) 有什么方法可以检测到您是在滚动到底部还是顶部(垂直滚动条开始变小时)

Thanks! 谢谢!

posting comment as answer: 发表评论作为答案:

Check the contentOffset in scrollviewDidScroll and the moment the contetOffset is beyond your bottom/top point, add new stuff to the scrollview, and increase the content size 检查scrollviewDidScrollcontentOffset ,以及当contetOffset超出底部/顶部时,将新内容添加到scrollview中,并增加内容大小

Maybe better solution would be something like this: 也许更好的解决方案是这样的:

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {

    if (targetContentOffset->y == 0 && scrollView.contentOffset.y < - someOffset) { //use someOffset if you dont want to reload immedeately on scroll to top
        //dragged past top
    }

    if (targetContentOffset->y == scrollView.contentSize.height && scrollView.contentOffset.y > scrollView.contentSize.height + someOffset) { 
        //dragged past bottom
    }

}

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

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