1

私は20個の配列画像を持っています。scroll view.scroll vertical 20 image を含むその画像 imageview を追加します。今私の要件は、スクロールする循環効果を与えることです

たとえば、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 に答える