iOS 14UIMenu似乎可以从 anyUIBarButtonItem或UIButton/呈现UIControl,但我如何从通用 呈现它UIView?
添加交互:
\nlet interaction = UIContextMenuInteraction(delegate: self)\nmenuView.addInteraction(interaction)\nRun Code Online (Sandbox Code Playgroud)\n将 UIContextMenuInteractionDelegate 添加到您的控制器:
\nextension YourViewController: UIContextMenuInteractionDelegate {\n \n func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {\n return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { suggestedActions in\n \n // Create an action for sharing\n let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in\n // Show system share sheet\n }\n \n // Create an action for renaming\n let rename = UIAction(title: "Rename", image: UIImage(systemName: "square.and.pencil")) { action in\n // Perform renaming\n }\n \n // Here we specify the "destructive" attribute to show that it\xe2\x80\x99s destructive in nature\n let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { action in\n // Perform delete\n }\n \n // Create and return a UIMenu with all of the actions as children\n return UIMenu(title: "", children: [share, rename, delete])\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n现在,长按视图并查看您的菜单:)
\n更多这里: https: //kylebashour.com/posts/context-menu-guide
\n| 归档时间: |
|
| 查看次数: |
3087 次 |
| 最近记录: |