Objective c 检测滚动过底部的UIScrollview
我正在尝试创建类似于Reeder的功能,如果您在滚动视图中滚动到内容下方或上方,您将了解新内容 我以为我在ScrollViewWillendDraging:withVelocity:targetContentOffset: 然而,这只是停留在底部 是否有任何方法可以检测您的滚动是否超出底部或顶部(此时垂直滚动条开始变小)Objective c 检测滚动过底部的UIScrollview,objective-c,ios,cocoa-touch,uiscrollview,uiscrollviewdelegate,Objective C,Ios,Cocoa Touch,Uiscrollview,Uiscrollviewdelegate,我正在尝试创建类似于Reeder的功能,如果您在滚动视图中滚动到内容下方或上方,您将了解新内容 我以为我在ScrollViewWillendDraging:withVelocity:targetContentOffset: 然而,这只是停留在底部 是否有任何方法可以检测您的滚动是否超出底部或顶部(此时垂直滚动条开始变小) 谢谢 将评论作为答案发布: 检查scrollviewDidScroll中的contentOffset,当contentOffset超出您的底部/顶部时,向scrollview添
谢谢 将评论作为答案发布:
检查
scrollviewDidScroll
中的contentOffset
,当contentOffset
超出您的底部/顶部时,向scrollview添加新内容,并增加内容大小将注释作为答案发布:
检查
scrollviewDidScroll
中的contentOffset
,当contentOffset
超出您的底/顶点时,向scrollview添加新内容,并增加内容大小也许更好的解决方案是这样的:
-(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
}
}
-(void)ScrollViewWillendDraging:(UIScrollView*)带速度的scrollView:(CGPoint)速度targetContentOffset:(inout CGPoint*)targetContentOffset{
如果(targetContentOffset->y==0&&scrollView.contentOffset.y<-someOffset){//如果不想在滚动到顶部时立即重新加载,请使用someOffset
//拖过山顶
}
如果(targetContentOffset->y==scrollView.contentSize.height&&scrollView.contentOffset.y>scrollView.contentSize.height+someOffset){
//拖过谷底
}
}
也许更好的解决方案是这样的:
-(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
}
}
-(void)ScrollViewWillendDraging:(UIScrollView*)带速度的scrollView:(CGPoint)速度targetContentOffset:(inout CGPoint*)targetContentOffset{
如果(targetContentOffset->y==0&&scrollView.contentOffset.y<-someOffset){//如果不想在滚动到顶部时立即重新加载,请使用someOffset
//拖过山顶
}
如果(targetContentOffset->y==scrollView.contentSize.height&&scrollView.contentOffset.y>scrollView.contentSize.height+someOffset){
//拖过谷底
}
}
为什么不在scrollviewDidScroll中检查contentOffset,当content offset超出您的底/顶点时,向scrollview添加新内容,并增加内容大小这就是诀窍。我通过获取contentOffset-scrollview内容大小-scrollview高度的值来解决这个问题:float diff=scrollview.contentOffset.y-(scrollview.contentSize.height-scrollview.frame.size.height);如果(diff>30){//做需要做的事情}为什么不在scrollviewDidScroll中检查contentOffset,当contentOffset超出您的底/顶点时,向scrollview添加新内容,并增加内容大小这就是诀窍。我通过获取contentOffset-scrollview内容大小-scrollview高度的值来解决这个问题:float diff=scrollview.contentOffset.y-(scrollview.contentSize.height-scrollview.frame.size.height);如果(diff>30){//做需要做的事情}