Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ Carthage/Build
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/test_output
.DS_Store
13 changes: 11 additions & 2 deletions ImageViewer/Transitions/ImageViewerDismissalTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ final class ImageViewerDismissalTransition: NSObject, UIViewControllerAnimatedTr
animatableImageview.frame = fromSuperView.convert(fromImageView.frame, to: nil)
animatableImageview.contentMode = .scaleAspectFit

fromView?.isHidden = true

// Do not hide the view by setting its 'isHidden' property. A UIStackView removes hidden subviews from the visual hierarchy. Therefore, the layout jumps when switched to visible after dismissal.
// fromView?.isHidden = true
fromView?.alpha = 0
fadeView.frame = containerView.bounds
fadeView.backgroundColor = .black

Expand All @@ -74,7 +77,11 @@ final class ImageViewerDismissalTransition: NSObject, UIViewControllerAnimatedTr
options: .curveEaseInOut,
animations: apply(state: .start),
completion: { _ in
self.fromView?.isHidden = false

// Do not hide the view by setting its 'isHidden' property. A UIStackView removes hidden subviews from the visual hierarchy. Therefore, the layout jumps when switched to visible after dismissal.
// self.fromView?.isHidden = false
self.fromView?.alpha = 1
self.toImageView.alpha = 1
self.animatableImageview.removeFromSuperview()
self.fadeView.removeFromSuperview()
self.transitionContext?.completeTransition(false)
Expand All @@ -88,9 +95,11 @@ final class ImageViewerDismissalTransition: NSObject, UIViewControllerAnimatedTr
animations: apply(state: .end),
completion: { _ in
self.toImageView.isHidden = false
self.toImageView.alpha = 1
self.fadeView.removeFromSuperview()
self.animatableImageview.removeFromSuperview()
self.fromView?.removeFromSuperview()
self.fromView?.alpha = 0
self.transitionContext?.completeTransition(true)
})
}
Expand Down
16 changes: 10 additions & 6 deletions ImageViewer/Transitions/ImageViewerPresentationTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ImageViewerPresentationTransition: NSObject, UIViewControllerAnimate
let containerView = transitionContext.containerView
let toView = transitionContext.view(forKey: UITransitionContextViewKey.to)!
let fromParentView = fromImageView.superview!

let imageView = AnimatableImageView()
imageView.image = fromImageView.image
imageView.frame = fromParentView.convert(fromImageView.frame, to: nil)
Expand All @@ -27,8 +27,10 @@ final class ImageViewerPresentationTransition: NSObject, UIViewControllerAnimate
fadeView.alpha = 0.0

toView.frame = containerView.bounds
toView.isHidden = true
fromImageView.isHidden = true
// toView.isHidden = true
// Do not hide the view by setting its 'isHidden' property. A UIStackView removes hidden subviews from the visual hierarchy. Therefore, the layout jumps when switched to visible after dismissal.
// fromImageView.isHidden = true
fromImageView.alpha = 0

containerView.addSubview(toView)
containerView.addSubview(fadeView)
Expand All @@ -39,14 +41,16 @@ final class ImageViewerPresentationTransition: NSObject, UIViewControllerAnimate
usingSpringWithDamping: 0.8,
initialSpringVelocity: 0,
options: .curveEaseOut, animations: {
imageView.contentMode = .scaleAspectFit
imageView.frame = containerView.bounds
fadeView.alpha = 1.0
imageView.contentMode = .scaleAspectFit
imageView.frame = containerView.bounds
fadeView.alpha = 1.0
}, completion: { _ in
toView.isHidden = false
toView.alpha = 1
fadeView.removeFromSuperview()
imageView.removeFromSuperview()
transitionContext.completeTransition(true)
})
}
}