如何在滚动视图上放大和缩小多个图像

时间:2012-03-29 12:25:40

标签: iphone uiscrollview

我有一个包含多个图像的滚动视图,我正在使用此代码。我有肖像尺寸(2121 x 2892)的肖像和(2112 x 1500)横向模式

scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;

scrollView.maximumZoomScale = 3.0f;
scrollView.minimumZoomScale = 1.0;

NSInteger numberOfViews = [arrayImages count];

for (int i = 0; i < numberOfViews; i++)
{
    CGFloat yOrigin = i * scrollView.frame.size.width;
    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(yOrigin  +30, 0, self.view.frame.size.width-60 , self.view.frame.size.height)];

    imageView.userInteractionEnabled = YES;
    imageView.image = [UIImage imageNamed:[arrayImages objectAtIndex:i]];
    [scrollView addSubview:imageView];
    imageView.userInteractionEnabled = YES;

}
[self.view addSubview:scrollView];

我想在双标签上实现缩放和缩小功能,并用两根手指移动。我看到很多样本申请,但我无法做同样的事情。如果有人有自己的代码请与我分享。

2 个答案:

答案 0 :(得分:0)

简单地将子视图添加到scrollview并在其中添加所有imageView。并在scrollview的委托方法,并做这样

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
  return view;
}

答案 1 :(得分:0)

  

我想在双标签上实现缩放和缩小功能,并用两根手指移动。

要在双击时放大,请查看this tutorial的手势识别器部分。

至于用两根手指移动,您可以使用UIPanGestureRecogniser进行2次触摸,并在识别平移时相应地更改滚动视图的contentOffset