Hello,
The Apple's doc shows how to use UIEditMenuInteraction , but it's in Swift. You can refer to the following code to convert it to C#:
(Since you haven't yet migrated the custom renderer to use Handlers, I added a custom UITextField in a .net-iOS project to simulate the Handler's platform view.)
UIEditMenuInteraction editMenuInteraction = new UIEditMenuInteraction(new CutomUIEditMenuInteractionDelegate());
if (UIDevice.CurrentDevice.CheckSystemVersion(16, 0)) { myentry.AddInteraction(editMenuInteraction!);// myentry is type of your
var longPress = new UILongPressGestureRecognizer(HandleLongClick);
longPress.AllowedTouchTypes = new NSNumber[] { 0,1,2,3 };
myentry.AddGestureRecognizer(longPress);
`
Longpress
private void HandleLongClick(UILongPressGestureRecognizer sender)
{
var location = sender.LocationInView(vc.View);//if there is a page in MAUI, this view should be page.handler.platformview (UIView)
var configuration = UIEditMenuConfiguration.Create(null, location);
// Present the edit menu interaction.
editMenuInteraction.PresentEditMenu(configuration);
}
UIEditMenuInteractionDelegate
public class CutomUIEditMenuInteractionDelegate : UIEditMenuInteractionDelegate
{
public CutomUIEditMenuInteractionDelegate()
{
}
public override UIMenu? GetMenu(UIEditMenuInteraction interaction, UIEditMenuConfiguration configuration, UIMenuElement[] suggestedActions)
{//custom menu
var indentationMenu = UIMenu.Create("Indentation", new UIAction[]
{
UIAction.Create("title", null,null,(action)=>{ }
)
});
var actions = suggestedActions;
actions.Append(indentationMenu);
var menu = UIMenu.Create(children: actions);
return menu;
}
}
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.