我有一个包含11张图像的滚动视图。我希望当它显示的最后一张图像(11)时,滚动视图结束,以返回第一张图像。任何想法我怎么能这样做?
我尝试过:
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
return YES;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
self.scrollView.contentOffset = CGPointMake(0,0);
}
但我没有;想要得到结果。
答案 0 :(得分:1)
首先,您需要检查滚动视图中的内容是否结束。如果结束,则将其内容偏移设置为0。
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
[self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentOffset.y)];
}
答案 1 :(得分:0)
使用这些来检查你是否滚动到底部或没有..我跳它帮助
-(void)scrollViewDidScroll: (UIScrollView*)scrollView
{
float scrollViewHeight = self.scrollView.frame.size.height;
float scrollContentSizeHeight = self.scrollView.contentSize.height;
float scrollOffset = self.scrollView.contentOffset.y;
if (scrollOffset == 0)
{
// then we are at the top
}
else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
{
// then we are at the end
[self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentOffset.y)];
}
}