Iphone 如何使用三个UIScrollview重复图像[两侧]

Iphone 如何使用三个UIScrollview重复图像[两侧],iphone,ios,image,uiscrollview,repeat,Iphone,Ios,Image,Uiscrollview,Repeat,我不想重复我的答案,在下面的页面中,我写了如何创建一个包含3个图像的滚动视图,可以在两个水平方向上无限滚动: 如果你能更准确地描述你的问题和你想要实现的目标,人们可以更容易地帮助你。你想要什么?什么不起作用?是什么阻止你添加它们?好的,我明白了。但是,是什么阻止您在XIB中再添加两个滚动视图呢?这就是ScrollViewDiEndDecelling中sender参数的用途:它允许您判断三个视图中的哪一个已完成减速。我认为您可以通过只使用一个scrollview来执行任何操作,而无需使用更多。只需

我不想重复我的答案,在下面的页面中,我写了如何创建一个包含3个图像的滚动视图,可以在两个水平方向上无限滚动:


如果你能更准确地描述你的问题和你想要实现的目标,人们可以更容易地帮助你。

你想要什么?什么不起作用?是什么阻止你添加它们?好的,我明白了。但是,是什么阻止您在XIB中再添加两个滚动视图呢?这就是ScrollViewDiEndDecelling中sender参数的用途:它允许您判断三个视图中的哪一个已完成减速。我认为您可以通过只使用一个scrollview来执行任何操作,而无需使用更多。只需为scrollview启用pagecontrol!!!
-(void)viewDidLoad 
{
    [super viewDidLoad];

    // add the last image (image4) into the first position
    [self addImageWithName:@"image4.jpg" atPosition:0];

    // add all of the images to the scroll view
    for (int i = 1; i < 5; i++)
    {
        [self addImageWithName:[NSString stringWithFormat:@"image%i.jpg",i] atPosition:i];
    }

    // add the first image (image1) into the last position
    [self addImageWithName:@"image1.jpg" atPosition:5];

    scrollView.contentSize = CGSizeMake(320, 2496);    
    [scrollView scrollRectToVisible:CGRectMake(0,416,320,416) animated:NO]; 
}

- (void)addImageWithName:(NSString*)imageString atPosition:(int)position {
    // add image to scroll view
    UIImage *image = [UIImage imageNamed:imageString];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(0,position*416,320, 416);
    [scrollView addSubview:imageView];
    [imageView release];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {    
    NSLog(@"%f",scrollView.contentOffset.y);
    // The key is repositioning without animation      
    if (scrollView.contentOffset.y == 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(0,1664,320,416) animated:NO];     
    }    
    else if (scrollView.contentOffset.y == 2080) {         
        // 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,416,320,416) animated:NO];         
    } 
}