Skip to content

moo611/iOS-ZoomingTransition

Repository files navigation

ZoomingTransition

CI Status Version License Platform

Example

example

Requirements

ios 10.0 , swift 5.0

How to use

1. Pod install

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) } }

3. Record the lastSelectedIndexPath when click the item of collectionview

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) } }

4. To make your viewcontroller as a "PopVC", just implement ZoomTransitionAnimatorDelegate

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 :)

Author

Desong

License

ZoomingTransition is available under the MIT license. See the LICENSE file for more info.

About

A library to make zooming transition easier

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •