我有主UIScrollView
mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
mainScrollView.pagingEnabled = YES;
imageScrollView.contentSize = CGSizeMake(320 * [myImage count], 440);
,其中包含多个子UIScrollView
,每个子UIScrollView
包含UIImageView
for (int i = 0; i < [myImage count]; i++)
{
imageView = [[UIImageView alloc] init];
[imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
NSString *strimage = [myImage objectAtIndex:i];
NSURL *imageUrl = [NSURL URLWithString:strimage];
[imageView setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"Placeholder"]];
imageView.frame = CGRectMake(0, 0, 320, 440);
subScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(320 * i, 0, 320, 440)];
subScrollView.contentSize =
CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
subScrollView.pagingEnabled = YES;
subScrollView.showsHorizontalScrollIndicator = NO;
subScrollView.showsVerticalScrollIndicator = NO;
subScrollView.delegate = self;
subScrollView.bouncesZoom = YES;
subScrollView.clipsToBounds = YES;
subScrollView.maximumZoomScale = 3.0;
subScrollView.minimumZoomScale = 1.0;
subScrollView.zoomScale = 1.0;
[mainScrollView addSubview:subScrollView];
[subScrollView addSubview:imageView];
}
,我实施
#pragma mark UIScrollViewDelegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
问题是,当我放大UIImageView
时,假设有3个子UIScrollView
,最后一个子UIScrollView
可以正常缩放UIImageView
,但是当我放大UIScrollView
时放大它,它缩放子UIImageView
而不是UIScrollView
,它会影响最后一个子UIImageView
也可以缩放,我做错了吗?
我怀疑在viewForZoomingInScrollView中,它只能缩放UIScrollView
(最后一个{{1}}}。
提前谢谢你:)
答案 0 :(得分:1)
最后我弄明白了,当我放大特定UIImageView
时,我只需要更新我的UIImageView
在 - (UIView *)viewForZoomingInScrollView :( UIScrollView *)scrollView如下:
#pragma mark -
#pragma mark UIScrollViewDelegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
for (UIImageView *iv in [scrollView subviews]) {
imageView = iv;
break;
}
return imageView;
}
希望它可以帮助那些在这一点上与我斗争的人,所以你不必浪费时间:)。