2

我有一个包含少量图像的集合视图。当我单击图像时,图像需要缩放并导航到视图控制器。为此,我使用了 ZoomTransitioning 库。 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
    }

}

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

4

0 回答 0