diff --git a/Tusker/Screens/Large Image/LargeImageViewController.swift b/Tusker/Screens/Large Image/LargeImageViewController.swift index fa3a68b4..868ea0b5 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.swift +++ b/Tusker/Screens/Large Image/LargeImageViewController.swift @@ -182,6 +182,8 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma return zoomRect } + // MARK: Interaction + func animateZoomOut() { UIView.animate(withDuration: 0.3, animations: { self.scrollView.zoomScale = self.scrollView.minimumZoomScale diff --git a/Tusker/Screens/Large Image/Transitions/LargeImageExpandAnimationController.swift b/Tusker/Screens/Large Image/Transitions/LargeImageExpandAnimationController.swift index 2388a58c..af28c647 100644 --- a/Tusker/Screens/Large Image/Transitions/LargeImageExpandAnimationController.swift +++ b/Tusker/Screens/Large Image/Transitions/LargeImageExpandAnimationController.swift @@ -39,11 +39,16 @@ class LargeImageExpandAnimationController: NSObject, UIViewControllerAnimatedTra return } - let ratio = image.size.width / image.size.height - let width = finalVCFrame.width - let height = width / ratio - let finalFrame = CGRect(x: finalVCFrame.midX - width / 2, y: finalVCFrame.midY - height / 2, width: width, height: height) - + var finalFrameSize = finalVCFrame.inset(by: fromVC.view.safeAreaInsets).size + let newWidth = finalFrameSize.width / image.size.width + let newHeight = finalFrameSize.height / image.size.height + if newHeight < newWidth { + finalFrameSize.width = newHeight * image.size.width + } else { + finalFrameSize.height = newWidth * image.size.height + } + let finalFrame = CGRect(origin: CGPoint(x: finalVCFrame.midX - finalFrameSize.width / 2, y: finalVCFrame.midY - finalFrameSize.height / 2), size: finalFrameSize) + let imageView = GIFImageView(frame: sourceInfo.frame) imageView.image = image if let gifData = toVC.animationGifData { diff --git a/Tusker/Screens/Large Image/Transitions/LargeImageShrinkAnimationController.swift b/Tusker/Screens/Large Image/Transitions/LargeImageShrinkAnimationController.swift index 6cd042f6..37e97b6b 100644 --- a/Tusker/Screens/Large Image/Transitions/LargeImageShrinkAnimationController.swift +++ b/Tusker/Screens/Large Image/Transitions/LargeImageShrinkAnimationController.swift @@ -33,14 +33,20 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra return } - let originalVCFrame = fromVC.view.frame - + let containerView = transitionContext.containerView - let ratio = image.size.width / image.size.height - let width = originalVCFrame.width - let height = width / ratio - let originalFrame = CGRect(x: originalVCFrame.midX - width / 2, y: originalVCFrame.midY - height / 2, width: width, height: height) + let originalVCFrame = fromVC.view.frame + var originalFrameSize = originalVCFrame.inset(by: fromVC.view.safeAreaInsets).size + let newWidth = originalFrameSize.width / image.size.width + let newHeight = originalFrameSize.height / image.size.height + if newHeight < newWidth { + originalFrameSize.width = newHeight * image.size.width + } else { + originalFrameSize.height = newWidth * image.size.height + } + let originalFrame = CGRect(origin: CGPoint(x: originalVCFrame.midX - originalFrameSize.width / 2, y: originalVCFrame.midY - originalFrameSize.height / 2), size: originalFrameSize) + let imageView = GIFImageView(frame: originalFrame) imageView.image = image if let gifData = fromVC.animationGifData {