图像缩放和从collectionView过渡到viewcontroller swift

时间:2017-04-05 08:16:22

标签: swift collectionview image-zoom xcode8.2

我有一个包含少量图像的集合视图。单击图像时,图像需要缩放并导航到viewcontroller。为此,我使用了ZoomTransitioning Library。 https://github.com/WorldDownTown/ZoomTransitioning  但我无法传输gif中给出的图像。我的xcode是8.2.1和swift 3.0。

我使用了演示中给出的所有代表,并使用了pod'ZoomTransitioning'。

 extension ImageCollection {

    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let cell = collectionView.cellForItem(at: indexPath) as! ImageCell
        selectedImageView = cell.imageView
    }
}


// MARK: - UICollectionViewDelegateFlowLayout

extension ImageCollection {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
        let space: CGFloat = 8.0
        let length = (collectionView.frame.width - space * 3.0) / 2.0
        return CGSize(width: length, height: length)
    }
}


// MARK: - ZoomTransitionSourceDelegate

extension ImageCollection: ZoomTransitionSourceDelegate {

    func transitionSourceImageView() -> UIImageView {
        return selectedImageView ?? UIImageView()
    }

    func transitionSourceImageViewFrame(forward: Bool) -> CGRect {
        guard let selectedImageView = selectedImageView else { return CGRect.zero }
        return selectedImageView.convert(selectedImageView.bounds, to: view)
    }

    func transitionSourceWillBegin() {
        selectedImageView?.isHidden = true
    }

    func transitionSourceDidEnd() {
        selectedImageView?.isHidden = false
    }

    func transitionSourceDidCancel() {
        selectedImageView?.isHidden = false
    }

}

任何帮助将不胜感激。 提前谢谢。

0 个答案:

没有答案