0

我在 UIScrollView 中添加了许多 UIImageView,启用了分页。我只需要缩放我点击缩放的图像,而不是缩放整个滚动视图。缩放特定图像也不会缩放其他子视图。

- (void)loadScrollViewWithImages {

scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * imageList.count, self.view.bounds.size.height);
scrollView.pagingEnabled = YES;
UIView *mainView = [[UIView alloc] initWithFrame:self.view.bounds];

CGFloat xPos = 0.0;
for (UIView *subView in scrollView.subviews) {
    [subView removeFromSuperview];
}

int i = 0;

for (NSDictionary *imageDetails in self.imageList) {

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xPos, 0.0, self.view.bounds.size.width, self.view.frame.size.height)];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    [imageView setClipsToBounds:YES];
    [mainView addSubview:imageView];
    xPos += self.view.bounds.size.width;

    [imageView setImageWithURL:[NSURL URLWithString:[imageDetails objectForKey:@"media_path"]]];

    [self.imageViewArray addObject:imageView];

    if(self.selectedImageIndex == i) {
        self.selectedImageView = imageView;
    }
    i++;
}
[mainView setFrame:CGRectMake(mainView.frame.origin.x, mainView.frame.origin.x,self.view.bounds.size.width * imageList.count, self.view.bounds.size.height)];
[scrollView addSubview:mainView];

}

我只想缩放选定的索引,但其他子视图也添加到屏幕上,没有缩放。

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [[[scrollView.subviews objectAtIndex:0] subviews] objectAtIndex:0] ;;

}

4

1 回答 1

0

为了实现这一点,您必须像您一样采用主滚动视图,而不是在此滚动视图中显示 imageView,您必须采用另一个滚动视图并显示图像,当用户尝试缩放图像时,只有选定的滚动视图会滚动。

于 2013-07-23T11:37:23.097 回答