There is an easy way to present a context menu in iOS 13/14 via UIContextMenuInteraction
:
anyUIView.addInteraction(UIContextMenuInteraction(delegate: self))
The problem for me with this is that it blurs out the whole user interface. Also, this only gets invoked via a long-press/Haptic Touch.
If I do not want the blur, there are action menus. As shown here https://developer.apple.com/documentation/uikit/menus_and_shortcuts/adopting_menus_and_uiactions_in_your_user_interface
This seems to present without a blur, yet it only seems to attach to a UIButton
or a UIBarButtonItem
.
let infoButton = UIButton() infoButton.showsMenuAsPrimaryAction = true infoButton.menu = UIMenu(options: .displayInline, children: []) infoButton.addAction(UIAction { [weak infoButton] (action) in infoButton?.menu = infoButton?.menu?.replacingChildren([new items go here...]) }, for: .menuActionTriggered)
Is there a way to attach a context menu to a UIView that invokes on long press and does not present with blur?
https://stackoverflow.com/questions/66810809/ios-14-context-menu-from-uiview-not-from-uibutton-or-uibarbuttonitem March 26, 2021 at 11:52AM
没有评论:
发表评论