连续缩放图像

时间:2012-02-16 06:44:57

标签: iphone uiscrollview uiimageview scroll uiimage

我需要在我的项目中连续滚动图像,即从图像的底部滚动后继续滚动到顶部应该从基座开始,依此类推,在某种循环中,我怎么能做到这一点?

由于

2 个答案:

答案 0 :(得分:1)

我给出了两个参考链接,用于自动滚动滚动视图,您也可以在这里获取源代码并在项目中实现它的惊人功能

1)Automatically scroll the scroll view

2)As par your requirement created post of like wise gallery.

这篇文章可能对你有用。

快乐编码 谢谢和问候,

@Samuel

答案 1 :(得分:1)

在这个例子中,我总共拍摄了5张图片

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