如何在全屏显示图像的滚动视图?

我实现了一个方法来显示黑色背景的全屏图像。 我想适应它的图像滚动视图。 用户应该能够在全屏模式下滚动并转到下一个图像。 我怎样才能做到这一点?

这是全屏显示UIImageView的代码。 这是工作。

- (void)setUserPictImageViewZoomed:(BOOL)zoom animated:(BOOL)animated { UIView *blackView = [self.view viewWithTag:128]; BOOL isZoomed = blackView != nil; // if our current state (isZoomed) matches the desired state (zoomed), then we're done if (isZoomed == zoom) return; NSTimeInterval duration = (animated)? 0.3 : 0.0; if (zoom) { blackView = [[UIView alloc] initWithFrame:self.view.frame]; blackView.backgroundColor = [UIColor blackColor]; blackView.tag = 128; blackView.alpha = 0.0; [self.view addSubview:blackView]; UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(unzoom:)]; [blackView addGestureRecognizer:tapGR]; UIImageView *zoomImageView = [[UIImageView alloc] initWithImage:self.userPictImageView.image]; zoomImageView.contentMode = UIViewContentModeScaleAspectFit; zoomImageView.tag = 129; zoomImageView.frame = [self.userPictImageView convertRect:self.userPictImageView.frame toView:blackView]; [blackView addSubview:zoomImageView]; [UIView animateWithDuration:duration animations:^{ zoomImageView.frame = blackView.bounds; blackView.alpha = 1.0; }]; } else { UIImageView *zoomImageView = (UIImageView *)[blackView viewWithTag:129]; [UIView animateWithDuration:duration animations:^{ zoomImageView.frame = self.userPictImageView.frame; blackView.alpha = 0.0; } completion:^(BOOL finished) { [blackView removeFromSuperview]; }]; } } - (void)unzoom:(UIGestureRecognizer *)gr { [self setUserPictImageViewZoomed:NO animated:YES]; } 

这是我的图像滚动查看

  //PageControl: as many pages as images int numberOfPicts = [prize.pictures count]; if (numberOfPicts >1) [pageControl setNumberOfPages:numberOfPicts]; else pageControl.hidden = YES; //Load images in the scrollview for (int i = 0; i < numberOfPicts; i++) { //Create an imageView object in every 'page' of the scrollView. CGRect frame; frame.origin.x = self.imagesScrollView.frame.size.width * i; frame.origin.y = 0; frame.size = self.imagesScrollView.frame.size; UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame]; imageView.contentMode = UIViewContentModeScaleAspectFit; imageView.image = [prize.pictures objectAtIndex:i]; [self.imagesScrollView addSubview:imageView]; } //Set the content size of the scrollview according to the total width of imageView objects. self.imagesScrollView.contentSize = CGSizeMake(self.imagesScrollView.frame.size.width * numberOfPicts, self.imagesScrollView.frame.size.height); 

}

我想你可以使用UICollectionView,它会更有效。

那么如何添加一个选定的图片属性:

 @property (strong, nonatomic) UIImageView *selected; 

在scrollview中给每个imageView一个tap:

  UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToZoom:)]; [imageView addGestureRecognizer:tap]; // in a loop for each imageView in the scrollview 

点击放大只是这样做:

 - (void)taptozoom:(UITapGestureRecognizer *)gr { self.selected = (UIImageView *)gr.view; [self setImageView:self.selected zoomed:YES animated:YES]; } 

修改发布的方法以获取图像视图参数:

 - (void)setImageView:(UIImageView *)imageView zoomed:(BOOL)zoom animated:(BOOL)animated { UIView *blackView = [self.view viewWithTag:128]; BOOL isZoomed = blackView != nil; // if our current state (isZoomed) matches the desired state (zoomed), then we're done if (isZoomed == zoom) return; NSTimeInterval duration = (animated)? 0.3 : 0.0; CGRect unzoomedFrame = [imageView.superview convertRect:imageView.frame toView:blackView]; if (zoom) { blackView = [[UIView alloc] initWithFrame:self.view.frame]; blackView.backgroundColor = [UIColor blackColor]; blackView.tag = 128; blackView.alpha = 0.0; [self.view addSubview:blackView]; UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(unzoom:)]; [blackView addGestureRecognizer:tapGR]; UIImageView *zoomImageView = [[UIImageView alloc] initWithImage:imageView.image]; zoomImageView.contentMode = UIViewContentModeScaleAspectFit; zoomImageView.tag = 129; zoomImageView.frame = unzoomedFrame; [blackView addSubview:zoomImageView]; [UIView animateWithDuration:duration animations:^{ zoomImageView.frame = blackView.bounds; blackView.alpha = 1.0; }]; } else { UIImageView *zoomImageView = (UIImageView *)[blackView viewWithTag:129]; [UIView animateWithDuration:duration animations:^{ zoomImageView.frame = unzoomedFrame; blackView.alpha = 0.0; } completion:^(BOOL finished) { [blackView removeFromSuperview]; }]; } } 

未缩放的水龙头可以通过选定的图像视图:

 - (void)unzoom:(UIGestureRecognizer *)gr { [self setImageView:self.selected zoomed:NO animated:YES]; }