- (void)viewDidLoad
{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
int numberOfImages = 32;
CGFloat currentX = 0.0f;
for (int i=1; i <= numberOfImages; i++) {
// create image
NSString *imageName = [NSString stringWithFormat:@"page-%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];
// put image on correct position
CGRect rect = imageView.frame;
rect.origin.x = currentX;
imageView.frame = rect;
// update currentX
currentX +=454; //mageView.frame.size.width;
[scrollView addSubview:imageView];
[imageView release];
}
[scrollView addGestureRecognizer:tapGesture];
scrollView.contentSize = CGSizeMake(currentX, 800);
scrollView.pagingEnabled=YES;
scrollView.userInteractionEnabled = YES;
scrollView.maximumZoomScale = 15;
scrollView.minimumZoomScale = 0.5;
scrollView.bounces = NO;
scrollView.bouncesZoom = NO;
scrollView.delegate = self;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:scrollView];
[scrollView release];
[super viewDidLoad];
}
}
在上面的代码中,当我使用单个图像应用缩放或点击事件时,它适用于此。但是当相同的事件适用于图像阵列然后不工作。为什么会这样?
答案 0 :(得分:0)
它安静的复杂实现放大这种图像流。无论如何,我会建议你一个想法,
将手势添加到每个imageView。在该方法中,添加一个新的scrollview,使用相应的imageView ..然后实现缩放。
修改强>
在tapgesture方法中,
1.找出当时可见的imageView。
2.然后使用该单一图像视图创建新的滚动视图。
3.在新的滚动视图中实现缩放功能。
4.缩小时,如果新的滚动视图大小等于实际值,请从超级视图中删除新的滚动视图,以便可以看到图像数组。
答案 1 :(得分:0)
最简单的方法是先创建a big wrapper view
,然后将其插入ScrollView
然后将所有imageView添加到wrapper view
。