【问题标题】:display images using uicollectionview with zoom enable [closed]使用带有缩放功能的uicollectionview显示图像[关闭]
【发布时间】:2015-08-12 11:21:13
【问题描述】:

我想使用集合视图显示一些图像。我在滚动视图中使用单元格内的滚动视图和图像视图。图像放大和缩小。当单元格被重用时,新的单元格滚动视图和图像视图大小与缩放的旧单元格相同。 当单元格重用滚动视图大小得到默认值时想要。 如何解决这个问题。

【问题讨论】:

    标签: ios objective-c uiscrollview uiimageview uicollectionview


    【解决方案1】:

    @hello 您必须在 Imageview 中设置手势并使用以下方法, 您可以使用手势轻松设置放大和缩小

    在 ViewDID..

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    
     scrollViewMain.maximumZoomScale = 5.0;
        scrollViewMain.minimumZoomScale = 1.0;
        scrollViewMain.clipsToBounds = NO;
        scrollViewMain.delegate = self;
    UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwice:)];
        // set number of taps required
        tapTwice.numberOfTapsRequired = 2;
    
        // now add the gesture recogniser to a view
        // this will be the view that recognises the gesture
        [scrollViewMain addGestureRecognizer:tapTwice];
    }
    //------For Zoom IN ScrollView-------------------------------------------------------
    -(UIView *)viewForZoomingInScrollView:(UIScrollView *)inScroll {
        //self.iPickedPicture.center = ivPicture.center;
        return _imgView;
    }
    
    
    - (void)tapOnce:(UIGestureRecognizer *)gesture
        {
            //on a single  tap, call zoomToRect in UIScrollView
            if ([scrollViewMain zoomScale] > 1.0)
            {
            float newScale = 1.0;
            CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
            [scrollViewMain zoomToRect:zoomRect animated:YES];
            }
            else
            {
                float newScale =  3.5;
                CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
                [scrollViewMain zoomToRect:zoomRect animated:YES];
    
            }
        }
        - (void)tapTwice:(UIGestureRecognizer *)gesture
        {
            //on a double tap, call zoomToRect in UIScrollView
            if ([scrollViewMain zoomScale] == 1.0) {
    
            float newScale = [scrollViewMain zoomScale] * 3.5;
            CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
            [scrollViewMain zoomToRect:zoomRect animated:YES];
            }else
            {
                float newScale = 1.0;
                CGRect zoomRect = [self zoomToCenter:newScale withCenter:[gesture locationInView:scrollViewMain]];
                [scrollViewMain zoomToRect:zoomRect animated:YES];
            }
    
        }
    
        - (CGRect)zoomToCenter:(float)scale withCenter:(CGPoint)center {
    
            CGRect zoomRect;
            zoomRect.size.height = scrollViewMain.frame.size.height / scale;
            zoomRect.size.width  = scrollViewMain.frame.size.width  / scale;
    
            zoomRect.origin.x = center.x - (zoomRect.size.width  / 2.0);
            zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);
    
            return zoomRect;
    
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-05
      • 2013-01-02
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多