检测UIScrollview底部到达 [英] Detect UIScrollview bottom reached
问题描述
我有一个带图像的UIScrollView,当用户滚动到scrollview的末尾时,我想更新内容。这是我的代码,用于检测何时到达滚动视图的底部:
I have a UIScrollView with images and when the user scrolls to the end of the scrollview i want to update the content. This is my code to detect when the bottom of the scrollview is reached:
以下代码在中实现scrollViewDidScroll:
委托
CGFloat scrollViewHeight = imagesScrollView.bounds.size.height;
CGFloat scrollContentSizeHeight = imagesScrollView.contentSize.height;
CGFloat bottomInset = imagesScrollView.contentInset.bottom;
CGFloat scrollViewBottomOffset = scrollContentSizeHeight + bottomInset - scrollViewHeight;
if(imagesScrollView.contentOffset.y > scrollViewBottomOffset){
[imagesView addSubview:imagesBottomLoadingView];
[self downloadImages];
}
我的问题是,当用户滚动到底部时,我的函数被多次调用,但我想只调用一次。我尝试使用imagesScrollView.contentOffset.y == scrollViewBottomOffset但是它不起作用并且没有调用该函数
My problem is that when the user scrolls to bottom, my function is called several times, but i want to call it only once. I tried with imagesScrollView.contentOffset.y == scrollViewBottomOffset but it doesn't work and the function is not called
推荐答案
你有没有想到添加一个布尔值。第一次调用方法时可能会更新它,也可能在用户向上滚动时更新它。
Have you thought of adding a boolean. update it when the method is called for the first time and maybe when user scrolls back up.
这篇关于检测UIScrollview底部到达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!