Created
September 13, 2017 20:30
-
-
Save jverkoey/51acf5e4246a317148fecb4e009716a7 to your computer and use it in GitHub Desktop.
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 start(with context: TransitionContext) { | |
guard let contextView = backDelegate.backContextView(for: self, | |
with: context.foreViewController) else { | |
return | |
} | |
guard let foreImageView = foreDelegate.foreContextView(for: self) else { | |
return | |
} | |
let snapshotter = TransitionViewSnapshotter(containerView: context.containerView) | |
context.defer { | |
snapshotter.removeAllSnapshots() | |
} | |
foreImageView.isHidden = true | |
context.defer { | |
foreImageView.isHidden = false | |
} | |
let imageSize = foreImageView.image!.size | |
let fitScale = min(foreImageView.bounds.width / imageSize.width, | |
foreImageView.bounds.height / imageSize.height) | |
let fitSize = CGSize(width: fitScale * imageSize.width, height: fitScale * imageSize.height) | |
let snapshotContextView = snapshotter.snapshot(of: contextView, | |
isAppearing: context.direction == .backward) | |
context.compose(with: FadeTransition(target: .foreView, style: .fadeIn)) | |
context.compose(with: SpringFrameTransition(target: .target(snapshotContextView), | |
size: fitSize)) | |
if let toolbar = foreDelegate.toolbar(for: self) { | |
context.compose(with: SlideUpTransition(target: .target(toolbar))) | |
} | |
// This transition doesn't directly produce any animations, so we inform the context that it is | |
// complete here, otherwise the transition would never complete: | |
context.transitionDidEnd() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment