ios 10.0 , swift 5.0
pod 'ZoomingTransition'2. To make your viewcontroller as a "PushVC", just extends ZoomPushVC ,and implement ZoomTransitionAnimatorDelegate
class MyPushVC : ZoomPushVC,ZoomTransitionAnimatorDelegate{ var lastSelectedIndexPath: IndexPath? = nil //your own code... func transitionWillStart() { guard let lastSelected = self.lastSelectedIndexPath else { return } self.collectionView.cellForItem(at: lastSelected)?.isHidden = true } func transitionDidEnd() { guard let lastSelected = self.lastSelectedIndexPath else { return } self.collectionView.cellForItem(at: lastSelected)?.isHidden = false } func referenceImage() -> UIImage? { guard let lastSelected = self.lastSelectedIndexPath, let cell = self.collectionView.cellForItem(at: lastSelected) as? CustomCell else { return nil } return cell.imageView.image } func imageFrame() -> CGRect? { guard let lastSelected = self.lastSelectedIndexPath, let cell = self.collectionView.cellForItem(at: lastSelected) as? CustomCell else { return nil } return FrameHelper.getTargerFrame(originalView: cell.imageView, targetView: self.view) } }class MyPushVC : ZoomPushVC,ZoomTransitionAnimatorDelegate{ //with the code above ... func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { self.lastSelectedIndexPath = indexPath let vc = PreviewVC() vc.image = self.slices[indexPath.row] self.navigationController?.pushViewController(vc, animated: true) } }class PreviewVC: UIViewController,ZoomTransitionAnimatorDelegate{ //...your own code //when back button clicked @objc func close(){ self.navigationController?.popViewController(animated: true) } func transitionWillStart() { // self.imageView.isHidden = true self.view.alpha = 0 } func transitionDidEnd() { // self.imageView.isHidden = true self.view.alpha = 1 } func referenceImage() -> UIImage? { return FrameHelper.getScreenshot(with: self.view) } func imageFrame() -> CGRect? { return self.view.frame } }That's it ! Then you will see the fantastic zooming transition :)
Desong
ZoomingTransition is available under the MIT license. See the LICENSE file for more info.
