I tried to create the demo with the code
import UIKit
class ViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.browserUserInterfaceStyle = .dark
let button = UIBarButtonItem(title: "First", style: .plain, target: nil, action: #selector(action(_:)))
let button2 = UIBarButtonItem(title: "Second", style: .plain, target: nil, action: #selector(action(_:)))
self.additionalLeadingNavigationBarButtonItems = [button, button2]
}
@objc func action(_ sender: UIBarButtonItem) {
showAlert(with: sender)
}
func showAlert(with button: UIBarButtonItem) {
let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let action = UIAlertAction(title: "Test", style: .default)
controller.addAction(action)
controller.addAction(action)
let presentationPopover = controller.popoverPresentationController
presentationPopover?.sourceItem = button
present(controller, animated: true)
}
}
But the action sheet is in the wrong position when the user taps the button bar. This issue only happens when the user switches between the share and recent options before tapping the bar button.