Array of Images display in UIScrollview and Paging successfully but cannot properly zoom-in images in scrollview

前端 未结 2 1392
伪装坚强ぢ
伪装坚强ぢ 2021-02-11 08:44

I am working on UIScrollview with ImageArray. Scrolling and paging are working but I not able to zoom each image. My code of image Scrollview is below :-

#define I

2条回答
  •  梦谈多话
    2021-02-11 09:07

    #define IMAGE_FOR_ZOOM_TAG (1)
    

    Call following custom method

    -(void) setupProductImageViewContainerUI
    {
        UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    
        if(self.dimView)
        {
            for(UIView *subView in self.dimView.subviews)
                [subView removeFromSuperview];
            [self.dimView removeFromSuperview]; self.dimView = nil;
        }
    
        self.dimView = [[UIView alloc] initWithFrame:window.bounds];
        self.dimView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.5];
        self.dimView.userInteractionEnabled = YES;
        [window addSubview:self.dimView];
    
        self.imgContainerView = [[UIView alloc] init];
        self.imgContainerView.frame = CGRectMake(0, 0, window.frame.size.width, window.frame.size.height);
        self.imgContainerView.backgroundColor = [UIColor whiteColor];
        [self.dimView addSubview:self.imgContainerView];
    
        UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:window.bounds];
        mainScrollView.pagingEnabled = YES;
        mainScrollView.delegate = self;
        mainScrollView.showsHorizontalScrollIndicator = NO;
        mainScrollView.showsVerticalScrollIndicator = NO;
        [self.imgContainerView addSubview:mainScrollView];
        CGRect innerScrollFrame = mainScrollView.bounds;
    
        IndexOfSlidingPhoto = 0;
        for(int i = 0 ; i < listOfImages.count; i++)
        {
            UIImage *imgProduct = [GeneralClass getImageForSreenFromScreenTable:@"" orCustomTable:@"" OrDefaultImga:[listOfImages objectAtIndex:i]];
            UIImageView *imageForZooming = [[UIImageView alloc] initWithImage:imgProduct];
            imageForZooming.frame = CGRectMake(0, 0, window.frame.size.width, window.frame.size.height);
            imageForZooming.tag = IMAGE_FOR_ZOOM_TAG;
            imageForZooming.contentMode = UIViewContentModeScaleAspectFit;
    
            UIScrollView *pageScrollView = [[UIScrollView alloc] initWithFrame:innerScrollFrame];
            pageScrollView.minimumZoomScale = 1.0f;
            pageScrollView.maximumZoomScale = 20;
            pageScrollView.zoomScale = 1.0f;
            pageScrollView.contentSize = imageForZooming.bounds.size;
            pageScrollView.delegate = self;
            pageScrollView.showsHorizontalScrollIndicator = NO;
            pageScrollView.showsVerticalScrollIndicator = NO;
            [pageScrollView addSubview:imageForZooming];        
            [mainScrollView addSubview:pageScrollView];
    
            if (i < listOfImages.count -1)
                innerScrollFrame.origin.x += innerScrollFrame.size.width;
    
        mainScrollView.contentSize = CGSizeMake(innerScrollFrame.origin.x + innerScrollFrame.size.width, mainScrollView.bounds.size.height);
    
    
        [window bringSubviewToFront:self.dimView];
    }
    
    #pragma Mark -
    #pragma Mark - UIScrollView Delegate Methods
    
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    {
        return [scrollView viewWithTag:IMAGE_FOR_ZOOM_TAG];
    }
    

提交回复
热议问题