Put image view in navigation controller so that close and share buttons are laid out properly (ignoring iPad traffic lights). Fixes #5260.

This commit is contained in:
Brent Simmons committed 2026-05-27 11:38:09 -07:00
1 parent 8c02fb3ba4
commit 98b05ca283
4 files changed
+33 -50

No files matched your search

+17 -8
View File
@@ -9,14 +9,14 @@
import UIKit
final class ImageViewController: UIViewController {
@IBOutlet var closeButton: UIButton!
@IBOutlet var shareButton: UIButton!
@IBOutlet var imageScrollView: ImageScrollView!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var titleBackground: UIVisualEffectView!
@IBOutlet var titleLeading: NSLayoutConstraint!
@IBOutlet var titleTrailing: NSLayoutConstraint!
private var shareButtonItem: UIBarButtonItem?
var image: UIImage!
var imageTitle: String?
var zoomedFrame: CGRect {
@@ -36,11 +36,19 @@ final class ImageViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
closeButton.imageView?.contentMode = .scaleAspectFit
closeButton.accessibilityLabel = NSLocalizedString("Close", comment: "Close")
shareButton.accessibilityLabel = NSLocalizedString("Share", comment: "Share")
let closeButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(done(_:)))
closeButtonItem.tintColor = Assets.Colors.primaryAccent
let shareButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(share(_:)))
shareButtonItem.tintColor = Assets.Colors.primaryAccent
navigationItem.leftBarButtonItem = closeButtonItem
navigationItem.rightBarButtonItem = shareButtonItem
self.shareButtonItem = shareButtonItem
imageScrollView.setup()
// The image viewer is full-screen, so the scroll view ignores
// the navigation bar and safe area insets. Otherwise the image is pushed down
// and doesn’t match the zoom transition’s target frame.
imageScrollView.contentInsetAdjustmentBehavior = .never
imageScrollView.imageScrollViewDelegate = self
imageScrollView.imageContentMode = .aspectFit
imageScrollView.initialOffset = .center
@@ -64,10 +72,11 @@ final class ImageViewController: UIViewController {
}
@IBAction func share(_ sender: Any) {
guard let image = image else { return }
guard let image else {
return
}
let activityViewController = UIActivityViewController(activityItems: [image], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = shareButton
activityViewController.popoverPresentationController?.sourceRect = shareButton.bounds
activityViewController.popoverPresentationController?.barButtonItem = shareButtonItem
present(activityViewController, animated: true)
}