我有20个阵列图像。添加包含滚动视图的图像imageview.scroll垂直20图像。现在我的要求是给滚动的循环效果
例如20 1 2 3 4之后的示例..同样显示图像。
我试过那个但不适合我
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender
{
NSLog(@"%f",scrollView.contentOffset.x);
// The key is repositioning without animation
if (scrollView.contentOffset.x == 0) {
// user is scrolling to the left from image 1 to image 4
// reposition offset to show image 4 that is on the right in the scroll view
// [scrollView scrollRectToVisible:CGRectMake(1280,0,320,416) animated:NO];
[scrollView scrollRectToVisible:CGRectMake(6080, 0, 320, 416) animated:NO];
}
else if (scrollView.contentOffset.x == 6400) {
// user is scrolling to the right from image 4 to image 1
// reposition offset to show image 1 that is on the left in the scroll view
[scrollView scrollRectToVisible:CGRectMake(0,0,320,416) animated:NO];
//[scrollView scrollRectToVisible:CGRectMake(0, 0, 0, 0) animated:YES];
}
}
提前帮助我,谢谢。
答案 0 :(得分:3)
将Apple的示例代码用于循环ScrollView http://developer.apple.com/library/ios/#samplecode/StreetScroller/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011102
否则
通过以下
替换您的代码- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender
{
NSLog(@"%f",self.scrollView.contentOffset.x);
// The key is repositioning without animation
if (self.scrollView.contentOffset.x == 0) {
// user is scrolling to the left from image 1 to image 4
// reposition offset to show image 4 that is on the right in the scroll view
// [scrollView scrollRectToVisible:CGRectMake(1280,0,320,416) animated:NO];
// [self.scrollView scrollRectToVisible:CGRectMake(6080, 0, 320, 416) animated:NO];
[self.scrollView setContentOffset:CGPointMake(6080, 0) animated:YES];
}
else if (self.scrollView.contentOffset.x == 6080) {
// user is scrolling to the right from image 4 to image 1
// reposition offset to show image 1 that is on the left in the scroll view
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
// [self.scrollView scrollRectToVisible:CGRectMake(0,0,320,416) animated:NO];
//[scrollView scrollRectToVisible:CGRectMake(0, 0, 0, 0) animated:YES];
}
}
它可能对你有帮助