diff --git a/custom-transitions.xcodeproj/project.pbxproj b/custom-transitions.xcodeproj/project.pbxproj index fcaca10..77ead16 100644 --- a/custom-transitions.xcodeproj/project.pbxproj +++ b/custom-transitions.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -102,6 +102,7 @@ BC78E7A026163BB500371773 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; BC78E7A026163BB500371773 /* Products */ = { isa = PBXGroup; @@ -241,8 +242,9 @@ BC78E79726163BB500371773 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftUpdateCheck = 1230; - LastUpgradeCheck = 1230; + LastUpgradeCheck = 1540; TargetAttributes = { BC78E79E26163BB500371773 = { CreatedOnToolsVersion = 12.3; @@ -370,6 +372,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -431,6 +434,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/custom-transitions/Transitions/TransitionManager.swift b/custom-transitions/Transitions/TransitionManager.swift index 8d34854..6c3cbed 100644 --- a/custom-transitions/Transitions/TransitionManager.swift +++ b/custom-transitions/Transitions/TransitionManager.swift @@ -17,7 +17,7 @@ final class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning { } func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { - return duration + duration } func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { @@ -36,14 +36,14 @@ final class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning { // MARK: - UINavigationControllerDelegate extension TransitionManager: UINavigationControllerDelegate { - func navigationController( - _ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, - from fromVC: UIViewController, - to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { + func navigationController(_ navigationController: UINavigationController, + animationControllerFor operation: UINavigationController.Operation, + from fromVC: UIViewController, + to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { self.operation = operation - if operation == .push { + if operation == .push || operation == .pop { return self } @@ -71,7 +71,7 @@ private extension TransitionManager { let albumsViewController = toViewController as? AlbumsViewController else { return } - dismissViewController(detailsViewController, to: albumsViewController) + dismissViewController(detailsViewController, to: albumsViewController, with: context) default: break @@ -84,7 +84,7 @@ private extension TransitionManager { let albumCell = fromViewController.currentCell, let albumCoverImageView = fromViewController.currentCell?.albumCoverImageView, let albumDetailHeaderView = toViewController.headerView - else { return} + else { return } toViewController.view.layoutIfNeeded() @@ -125,7 +125,47 @@ private extension TransitionManager { animator.startAnimation() } - func dismissViewController(_ fromViewController: AlbumDetailViewController, to toViewController: AlbumsViewController) { + func dismissViewController(_ fromViewController: AlbumDetailViewController, to toViewController: AlbumsViewController, with context: UIViewControllerContextTransitioning) { + guard + let albumCell = toViewController.currentCell, + let albumCoverImageView = toViewController.currentCell?.albumCoverImageView, + let albumDetailHeaderView = fromViewController.headerView, + let albumDetailRootView = fromViewController.view + else { return } + + toViewController.view.layoutIfNeeded() + let containerView = context.containerView + + let snapshotContentView = UIView() + snapshotContentView.backgroundColor = albumDetailRootView.backgroundColor + snapshotContentView.frame = albumDetailRootView.frame + snapshotContentView.layer.cornerRadius = albumCell.contentView.layer.cornerRadius + + let snapshotAlbumCoverImageView = UIImageView() + snapshotAlbumCoverImageView.clipsToBounds = true + snapshotAlbumCoverImageView.contentMode = albumDetailHeaderView.contentMode + snapshotAlbumCoverImageView.image = albumDetailHeaderView.albumCoverImageView.image + snapshotAlbumCoverImageView.layer.cornerRadius = albumDetailHeaderView.layer.cornerRadius + snapshotAlbumCoverImageView.frame = containerView.convert(albumDetailHeaderView.albumCoverImageView.frame, from: albumDetailHeaderView) + + containerView.addSubview(toViewController.view) + containerView.addSubview(snapshotContentView) + containerView.addSubview(snapshotAlbumCoverImageView) + + let animator = UIViewPropertyAnimator(duration: duration, curve: .easeInOut) { + snapshotContentView.frame = containerView.convert(albumCell.contentView.frame, from: albumCell) + snapshotContentView.backgroundColor = albumCell.contentView.backgroundColor + snapshotAlbumCoverImageView.frame = containerView.convert(albumCoverImageView.frame, from: albumCell) + snapshotAlbumCoverImageView.layer.cornerRadius = albumCoverImageView.layer.cornerRadius + } + + animator.addCompletion { position in + snapshotAlbumCoverImageView.removeFromSuperview() + snapshotContentView.removeFromSuperview() + context.completeTransition(position == .end) + } + + animator.startAnimation() } } diff --git a/custom-transitions/View/AlbumDetailHeaderView.swift b/custom-transitions/View/AlbumDetailHeaderView.swift index c7b90eb..df474af 100644 --- a/custom-transitions/View/AlbumDetailHeaderView.swift +++ b/custom-transitions/View/AlbumDetailHeaderView.swift @@ -7,7 +7,7 @@ import UIKit -protocol AlbumDetailHeaderViewDelegate: class { +protocol AlbumDetailHeaderViewDelegate: AnyObject { func closeButtonDidTap() } diff --git a/custom-transitions/ViewController/AlbumsViewController.swift b/custom-transitions/ViewController/AlbumsViewController.swift index faa4d2b..d690ede 100644 --- a/custom-transitions/ViewController/AlbumsViewController.swift +++ b/custom-transitions/ViewController/AlbumsViewController.swift @@ -43,9 +43,8 @@ class AlbumsViewController: UIViewController { } override func viewDidAppear(_ animated: Bool) { - + super.viewDidAppear(animated) } - } // MARK: - Setups