Posts

Post not yet marked as solved
0 Replies
836 Views
import UIKit class ViewController: UIViewController { let imageView = UIImageView(image: UIImage(named: "image")) override func viewDidLoad() { super.viewDidLoad() imageView.isUserInteractionEnabled = true imageView.frame = CGRect(x: 0, y: 0, width: 384, height: 288) imageView.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height / 2) let interaction = UIContextMenuInteraction(delegate: self) imageView.addInteraction(interaction) view.addSubview(imageView) } } extension ViewController: UIContextMenuInteractionDelegate { func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in return self.makeContextMenu() }) } func makeContextMenu() -> UIMenu { let rename = UIAction(title: "Rename", image: UIImage(systemName: "square.and.pencil")) { action in // Show rename UI } let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { action in // Delete this photo } let edit = UIMenu(title: "Edit...", children: [rename, delete]) let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in // Show system share sheet } return UIMenu(title: "Main Menu", children: [edit, share]) } }I wanted to try the new iOS 13 Context Menu. When I use this app in the Simulator or on real devices, the app crash when I Haptic Touch / Long Press the Image. I also get an error in line 41 (33 in the code above). I don't think there is something wrong in this line. Did I made a mistake or is the context menu still under development? I have used the newest version of Xcode-beta (Version 11.0 beta 4 (11M374r)) and the newest version of iOS (13.0 (17A5534f)).Console output:
Posted
by mrleaw.
Last updated
.