iPad OS, Beta 5
Adding custom menu items to UIMenuController.shared.menuItems does not work in PDFKit on Beta 5. It does work in UITextView. It used to work in previous OS releases.
1. Add menu item(s) to UIMenuController.shared.menuItems
2. Select Text
Result: Built-in edit menu items appear, but any items added programmatically do not.
Expected Result: Both built in and items added programattically appear.
SAMPLE Code to demonstrate follows:
extension Selector {
static let customAction = #selector(ViewController.customAction(menuItem :))
}
class ViewController: UIViewController {
@objc func customAction(menuItem : UIMenuItem) {
print("Custom Action")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let customItem = UIMenuItem(title: "My MenuItem", action: .customAction)
UIMenuController.shared.menuItems = [customItem]
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let path = Bundle.main.path(forResource: "Psych", ofType: "pdf")
let pdfView = PDFView(frame: view.bounds)
view.addSubview(pdfView)
pdfView.document = PDFDocument(url: URL(fileURLWithPath: path!))
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
let canShow = action == .customAction
print(action.description + " \(canShow)")
return canShow
}
}