- - (void)cuLayoutSubViews
- {
- BL_LoadNavHeight;
- self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth_N(), ScreenHeight_N())];
- self.scrollView.backgroundColor = [UIColor blackColor];
- [self.view addSubview:self.scrollView];
-
- self.scrollView.delegate = self;
- self.scrollView.pagingEnabled = YES;
- self.scrollView.scrollEnabled = YES;
- self.scrollView.showsHorizontalScrollIndicator = NO;
-
- [self.imageArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
-
- UIScrollView *subScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(idx*ScreenWidth_N(), navViewH, ScreenWidth_N(), ScreenHeight_N()-navViewH)];
- subScrollView.backgroundColor = [UIColor blackColor];
- subScrollView.contentSize = CGSizeMake(ScreenWidth_N(), ScreenHeight_N()-navViewH);
- subScrollView.delegate = self;
- subScrollView.minimumZoomScale = self.minScale;
- subScrollView.maximumZoomScale = self.maxScale;
- [subScrollView setZoomScale:1.0];
-
- UIImage *img = (UIImage *)obj;
- UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth_N(), ScreenHeight_N()-navViewH)];
- imgView.userInteractionEnabled = YES;
- imgView.contentMode = UIViewContentModeScaleAspectFit;
- imgView.image = img;
-
- UIPinchGestureRecognizer *pin = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinGesClick:)];
- //捏合手势
- [imgView addGestureRecognizer:pin];
- [subScrollView addSubview:imgView];
- [self.scrollView addSubview:subScrollView];
-
- [self.subScrollViewArr addObject:subScrollView];
- [self.imgViewArr addObject:imgView];
-
- }];
-
- [self adjustScrollViewOffset];
-
- // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(navHidden)];
- // [self.scrollView addGestureRecognizer:tap];
- }
- - (void)pinGesClick:(UIPinchGestureRecognizer *)pinGes
- {
- // switch (pinGes.state) {
- // case UIGestureRecognizerStateBegan://scale began
- // case UIGestureRecognizerStateChanged://scale changed
- // {
- // CGFloat currentScale = [[self.scrollView.layer valueForKeyPath:@"transform.scale"] floatValue];
- // CGFloat newScale = pinGes.scale - self.lastScale + 1;
- //
- // newScale = MIN(newScale, self.maxScale / currentScale);
- // newScale = MAX(newScale, self.minScale / currentScale);
- //
- // self.scrollView.transform = CGAffineTransformScale(self.scrollView.transform, newScale, newScale);
- //
- // for (int i = 0; i < self.imgViewArr.count; i++) {
- // UIImageView *subImgView = self.imgViewArr[i];
- // NSLog(@"subImgView----%d---%@", i, subImgView);
- // }
- //
- // self.lastScale = pinGes.scale;
- //
- //
- // }
- // break;
- // case UIGestureRecognizerStateEnded://scale ended
- // self.lastScale = 1;
- // break;
- // default:
- // break;
- // }
-
- float newScale = [(UIScrollView*)pinGes.view.superview zoomScale];
- CGRect zoomRect = [self zoomRectForScale:newScale inView:(UIScrollView*)pinGes.view.superview withCenter:[pinGes locationInView:pinGes.view]];
- [(UIScrollView*)pinGes.view.superview zoomToRect:zoomRect animated:YES];
- }
- //放回当前缩放图片
- - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
- {
- for (UIView *v in scrollView.subviews){
- return v;
- }
- return nil;
- }