1

我有 20 个数组图像。添加包含滚动视图的图像图像视图。垂直滚动 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];
    }
}

提前帮我解决这个问题。

4

1 回答 1

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];
    }
}

它可能会帮助你

于 2013-05-27T11:41:56.633 回答