This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomInteractor : UIPercentDrivenInteractiveTransition { | |
var navigationController : UINavigationController | |
var shouldCompleteTransition = false | |
var transitionInProgress = false | |
init?(attachTo viewController : UIViewController) { | |
if let nav = viewController.navigationController { | |
self.navigationController = nav | |
super.init() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
guard let frame = self.selectedFrame else { return nil } | |
guard let song = self.selectedSong else { return nil } | |
switch operation { | |
case .push: | |
return CustomAnimator(duration: TimeInterval(UINavigationControllerHideShowBarDuration), isPresenting: true, originFrame: frame, image: song.artwork) | |
default: | |
return CustomAnimator(duration: TimeInterval(UINavigationControllerHideShowBarDuration), isPresenting: false, originFrame: frame, image: song.artwork) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
self.selectedSong = songs[indexPath.row] | |
let theAttributes:UICollectionViewLayoutAttributes! = collectionView.layoutAttributesForItem(at: indexPath) | |
selectedFrame = collectionView.convert(theAttributes.frame, to: collectionView.superview) | |
self.performSegue(withIdentifier: "Player", sender: self) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.navigationController?.delegate = self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomAnimator : NSObject, UIViewControllerAnimatedTransitioning { | |
var duration : TimeInterval | |
var isPresenting : Bool | |
var originFrame : CGRect | |
var image : UIImage | |
public let CustomAnimatorTag = 99 | |
init(duration : TimeInterval, isPresenting : Bool, originFrame : CGRect, image : UIImage) { | |
self.duration = duration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIView.animate(withDuration: duration, animations: { | |
transitionImageView.frame = self.isPresenting ? artwork.frame : self.originFrame | |
detailView.frame = self.isPresenting ? fromView.frame : CGRect(x: toView.frame.width, y: 0, width: toView.frame.width, height: toView.frame.height) | |
detailView.alpha = self.isPresenting ? 1 : 0 | |
}, completion: { (finished) in | |
transitionContext.completeTransition(!transitionContext.transitionWasCancelled) | |
transitionImageView.removeFromSuperview() | |
artwork.alpha = 1 | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let transitionImageView = UIImageView(frame: isPresenting ? originFrame : artwork.frame) | |
transitionImageView.image = image | |
container.addSubview(transitionImageView) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let artwork = detailView.viewWithTag(CustomAnimatorTag) as? UIImageView else { return } | |
artwork.image = image | |
artwork.alpha = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public let CustomAnimatorTag = 99 | |