Fix incorrect large image size during expand/shrink animation in some

cases
This commit is contained in:
Shadowfacts 2020-03-25 22:09:00 -04:00
parent 8a513186aa
commit 49a437583e
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 24 additions and 11 deletions

View File

@ -182,6 +182,8 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
return zoomRect return zoomRect
} }
// MARK: Interaction
func animateZoomOut() { func animateZoomOut() {
UIView.animate(withDuration: 0.3, animations: { UIView.animate(withDuration: 0.3, animations: {
self.scrollView.zoomScale = self.scrollView.minimumZoomScale self.scrollView.zoomScale = self.scrollView.minimumZoomScale

View File

@ -39,11 +39,16 @@ class LargeImageExpandAnimationController: NSObject, UIViewControllerAnimatedTra
return return
} }
let ratio = image.size.width / image.size.height var finalFrameSize = finalVCFrame.inset(by: fromVC.view.safeAreaInsets).size
let width = finalVCFrame.width let newWidth = finalFrameSize.width / image.size.width
let height = width / ratio let newHeight = finalFrameSize.height / image.size.height
let finalFrame = CGRect(x: finalVCFrame.midX - width / 2, y: finalVCFrame.midY - height / 2, width: width, height: 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) let imageView = GIFImageView(frame: sourceInfo.frame)
imageView.image = image imageView.image = image
if let gifData = toVC.animationGifData { if let gifData = toVC.animationGifData {

View File

@ -33,14 +33,20 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra
return return
} }
let originalVCFrame = fromVC.view.frame
let containerView = transitionContext.containerView 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) let imageView = GIFImageView(frame: originalFrame)
imageView.image = image imageView.image = image
if let gifData = fromVC.animationGifData { if let gifData = fromVC.animationGifData {