Iphone 对于ios7中的多个图像,在UIScrollview中收缩缩放不起作用

Iphone 对于ios7中的多个图像,在UIScrollview中收缩缩放不起作用,iphone,xcode,uiscrollview,ios7,Iphone,Xcode,Uiscrollview,Ios7,我想在uiscrollview图像中收缩缩放。我在uiscrollview中添加了多个图像 但是收缩缩放不起作用,我想收缩缩放图像查看图像。我参考了这么多参考资料,但仍然不起作用 提前谢谢 我的代码:- for(int i = 0;i<aryImage.count;i++) { //Create a uiimageview imageView =[[UIImageView alloc]init ]

我想在uiscrollview图像中收缩缩放。我在uiscrollview中添加了多个图像 但是收缩缩放不起作用,我想收缩缩放图像查看图像。我参考了这么多参考资料,但仍然不起作用

提前谢谢

我的代码:-

for(int i = 0;i<aryImage.count;i++)
            {

                 //Create a uiimageview

                imageView =[[UIImageView alloc]init ];

                imageView.frame = CGRectMake((280 *i),0.0, 280, 475);
                imageView.image = [UIImage imageNamed:@"default.png"];
                imageView.tag = i;
                imageView.userInteractionEnabled = YES;
                [scrollGallery addSubview:imageView];

                scrollGallery.minimumZoomScale = 1.0;

                scrollGallery.maximumZoomScale = 2.0;

                scrollGallery.delegate = self;

               [scrollGallery addSubview:imageView];

            }
            scrollGallery.contentSize = CGSizeMake(280 * aryImage.count, scrollGallery.frame.size.height);
            pageControl.numberOfPages = aryImage.count;
            pageControlBeingUsed = NO;
            pageControl.currentPage = 0;




- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return imageView;
}
for(inti=0;i试试这个:

- (void)scrollViewDidZoom:(UIScrollView *)sv
{
    UIView* zoomView = [sv.delegate viewForZoomingInScrollView:sv];
    CGRect zvf = zoomView.frame;
    if(zvf.size.width < sv.bounds.size.width)
    {
        zvf.origin.x = (sv.bounds.size.width - zvf.size.width) / 2.0;
    }
    else
    {
        zvf.origin.x = 0.0;
    }
    if(zvf.size.height < sv.bounds.size.height)
    {
        zvf.origin.y = (sv.bounds.size.height - zvf.size.height) / 2.0;
    }
    else
    {
        zvf.origin.y = 0.0;
    }
    zoomView.frame = zvf;
}
-(无效)scrollViewDidZoom:(UIScrollView*)sv
{
UIView*zoomView=[sv.delegate viewForZoomingInScrollView:sv];
CGRect zvf=zoomView.frame;
if(zvf.size.width
在视图中仅返回一个用于缩放的imageView,但添加了它们的数组。这可能是问题的原因。请尝试按如下方式替换代码:

UIView *containerView = [[UIView alloc] initWithFrame:scrollGallery.frame];
[scrollGallery addSubview:containerView];
scrollGallery.minimumZoomScale = 1.0;
scrollGallery.maximumZoomScale = 2.0;
scrollGallery.delegate = self;

for(int i = 0;i<aryImage.count;i++)
        {

             //Create a uiimageview

            imageView =[[UIImageView alloc]init ];

            imageView.frame = CGRectMake((280 *i),0.0, 280, 475);
            imageView.image = [UIImage imageNamed:@"default.png"];
            imageView.tag = i;
            imageView.userInteractionEnabled = YES;
            [containerView addSubview:imageView];
        }
        scrollGallery.contentSize = CGSizeMake(280 * aryImage.count, scrollGallery.frame.size.height);

        // then maybe you need to resize containerView's frame
        //..........

        pageControl.numberOfPages = aryImage.count;
        pageControlBeingUsed = NO;
        pageControl.currentPage = 0;


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return containerView;
}
使用


不要忘记在最后发布所有内容;)

我使用yr代码,它对我有效,但当我缩放第三幅图像时,它不会缩放,它只缩放第一幅图像:)你确定要将第三幅图像添加到容器视图而不是滚动视图吗?@hatfinch是的,我在容器视图中添加所有图像,当我缩放第三幅图像时,它只返回第一幅图像:)imageView对象可能会在中释放循环导致您在下一次迭代中将其替换为另一个对象。见上文UPD2。
NSMutableArray *arr = [[NSMutableArray alloc] init];
for (int i=0; i<aryImage.count; i++) {
    [arr addObject:[[UIImageView alloc] init]];
}
imageView =[[UIImageView alloc] init];
UIImageView *imageView = [arr objectAtIndex:i];