Skip to content

Instantly share code, notes, and snippets.

@jverkoey
Created September 13, 2017 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jverkoey/51acf5e4246a317148fecb4e009716a7 to your computer and use it in GitHub Desktop.
Save jverkoey/51acf5e4246a317148fecb4e009716a7 to your computer and use it in GitHub Desktop.
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