简体   繁体   English

单元格中单个 UIImageView 的 UICollectionVIew 缩放

[英]UICollectionVIew zoom of a single UIImageView in a cell

How to zoom a UIImageView that takes up a fullscreen cell in a UICollectionView image?如何缩放占据 UICollectionView 图像中全屏单元格的 UIImageView?

Since UICollectionView is a subclass of UIScrollView it should be fairly simple..由于 UICollectionView 是 UIScrollView 的子类,所以它应该相当简单..

I tried to set minimumZoomScale, maximumZoomScale and viewForZoomingInScrollView: but the result is a mess.我试图设置 minimumZoomScale、maximumZoomScale 和 viewForZoomingInScrollView: 但结果是一团糟。

In viewForZoomingInScrollView i returned the UIImageView, but that does not work.在 viewForZoomingInScrollView 中,我返回了 UIImageView,但这不起作用。

Now i'm trying to return the visualized cell, but on zooming the image changes to the first cell.现在我正在尝试返回可视化的单元格,但是在缩放图像时会更改为第一个单元格。

it zooms but messes up the collection view.它会放大但弄乱了集合视图。

func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {

    if let selectedIndex = self.collectionView.indexPathsForVisibleItems().last as? NSIndexPath
    {
        let cell = self.collectionView.cellForItemAtIndexPath(selectedIndex)
        return cell
    }
    return nil
}

So, what i need to do to zoom the image (cell) currently on screen?那么,我需要做什么来缩放当前屏幕上的图像(单元格)?

Moreover pagingEnabled goes off automatically (that's good for panning the zoomed image, but not for scrolling the collection)此外, pagingEnabled 会自动关闭(这有利于平移缩放的图像,但不适用于滚动集合)

您需要在 UICollectionView 的单元格内放置一个新的 UIScrollView,因为您不应该弄乱 CollectionView 本身的缩放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM