如何在 iCarousel 视图中单击缩放图像?

Posted

技术标签:

【中文标题】如何在 iCarousel 视图中单击缩放图像?【英文标题】:How to Zoom Image on single tap in an iCarousel View? 【发布时间】:2016-05-31 10:53:43 【问题描述】:

我正在努力通过单击放大图像,但还没有成功。我有一个带有 6 张图像的轮播视图,效果很好,但我希望在轮播视图中点击图像时特定图像可以缩放/弹出。任何帮助将不胜感激。

【问题讨论】:

【参考方案1】:

首先在您的UIImageView 中声明TapGestureRegcognizer 然后addSubview。在您的viewDidLoad 中使用此代码:

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];

[doubleTap setNumberOfTapsRequired:1];

[imageview addGestureRecognizer:doubleTap];

那么如果你点击UIImageView单击,调用下面的方法是,

    - (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer 
        // zoom in
        float newScale = [myscrollview zoomScale] * 2;

        if (newScale > self.myscrollview.maximumZoomScale)
            newScale = self.myscrollview.minimumZoomScale;
            CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];

            [myscrollview zoomToRect:zoomRect animated:YES];

        
        else

            newScale = self.myscrollview.maximumZoomScale;
            CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];

            [myscrollview zoomToRect:zoomRect animated:YES];
        
    

- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center 

    CGRect zoomRect;

    // the zoom rect is in the content view's coordinates.
    //    At a zoom scale of 1.0, it would be the size of the imageScrollView's bounds.
    //    As the zoom scale decreases, so more content is visible, the size of the rect grows.
    zoomRect.size.height = [myscrollview frame].size.height / scale;
    zoomRect.size.width  = [myscrollview frame].size.width  / scale;

    // choose an origin so as to get the right center.
    zoomRect.origin.x    = center.x - (zoomRect.size.width  / 2.0);
    zoomRect.origin.y    = center.y - (zoomRect.size.height / 2.0);

    return zoomRect;

它对我有用,希望它有帮助。

【讨论】:

嗨@Iyyappan,我试过这个..它有效,我想要的是“旋转木马视图中的图像”进行缩放。

以上是关于如何在 iCarousel 视图中单击缩放图像?的主要内容,如果未能解决你的问题,请参考以下文章

在 iCarousel 的 iCarouselTypeRotary 视图中隐藏图像

iCarousel 上的缩放变换显示屏幕外的区域

索引iCarousel中UIView的多选

为啥当我切换到上一个屏幕时,iCarousel 视图中的图像会显示在上一个屏幕中?

在 iCarousel 中添加独立的进度视图以指示下载

Android:谷歌照片,如具有缩放功能的网格视图