diff --git a/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift b/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift index 8432ddade..7df8861b0 100644 --- a/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift +++ b/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift @@ -128,23 +128,14 @@ extension MediaPreviewImageView { // reset to normal zoomScale = minimumZoomScale - let imageViewSize = AVMakeRect(aspectRatio: image.size, insideRect: container.bounds).size - let imageContentInset: UIEdgeInsets = { - if imageViewSize.width == container.bounds.width { - return UIEdgeInsets(top: 0.5 * (container.bounds.height - imageViewSize.height), left: 0, bottom: 0, right: 0) - } else { - return UIEdgeInsets(top: 0, left: 0.5 * (container.bounds.width - imageViewSize.width), bottom: 0, right: 0) - } - }() + let imageViewSize = AVMakeRect(aspectRatio: image.size, insideRect: container.bounds.inset(by: container.safeAreaInsets)).size imageView.frame = CGRect(origin: .zero, size: imageViewSize) if imageView.image == nil { imageView.image = image } contentSize = imageViewSize - contentInset = imageContentInset centerScrollViewContents() - contentOffset = CGPoint(x: -contentInset.left, y: -contentInset.top) if #available(iOS 16.0, *) { Task.detached(priority: .userInitiated) { @@ -224,10 +215,7 @@ extension MediaPreviewImageView { frame.size = realImageSize imageView.frame = frame - let screenSize = self.frame.size - let offsetX = screenSize.width > realImageSize.width ? (screenSize.width - realImageSize.width) / 2 : 0 - let offsetY = screenSize.height > realImageSize.height ? (screenSize.height - realImageSize.height) / 2 : 0 - contentInset = UIEdgeInsets(top: offsetY, left: offsetX, bottom: offsetY, right: offsetX) + contentInset = self.safeAreaInsets // The scroll view has zoomed, so you need to re-center the contents let scrollViewSize = scrollViewVisibleSize diff --git a/Mastodon/Scene/Transition/MediaPreview/MediaHostToMediaPreviewViewControllerAnimatedTransitioning.swift b/Mastodon/Scene/Transition/MediaPreview/MediaHostToMediaPreviewViewControllerAnimatedTransitioning.swift index ed0503502..ace6048c5 100644 --- a/Mastodon/Scene/Transition/MediaPreview/MediaHostToMediaPreviewViewControllerAnimatedTransitioning.swift +++ b/Mastodon/Scene/Transition/MediaPreview/MediaHostToMediaPreviewViewControllerAnimatedTransitioning.swift @@ -65,7 +65,7 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning { let initialFrame = transitionItem.initialFrame ?? toViewEndFrame let transitionTargetFrame: CGRect = { let aspectRatio = transitionItem.aspectRatio ?? CGSize(width: initialFrame.width, height: initialFrame.height) - return AVMakeRect(aspectRatio: aspectRatio, insideRect: toView.bounds) + return AVMakeRect(aspectRatio: aspectRatio, insideRect: toView.bounds.inset(by: toView.safeAreaInsets)) }() let transitionImageView: UIImageView = { let imageView = UIImageView(frame: transitionContext.containerView.convert(initialFrame, from: nil))