Sunday, October 15, 2023
HomeiOS Developmentios - How can I present the UIMenu programmatically?

ios – How can I present the UIMenu programmatically?


I’ve assigned two UILongPressGestureRecognizer objects to a UIButton.

First one, is known as longPressGestureRecognizer and has minimumPressDuration = 0.5

Second one, is known as prolongedPressGestureRecognizer and has minimumPressDuration = 1.5

self.longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self motion:@selector(longPress:)];

        self.longPressGestureRecognizer.delegate = self;
        
        self.longPressGestureRecognizer.minimumPressDuration = 0.5;
        
        self.longPressGestureRecognizer.numberOfTouchesRequired = 1;
        
        self.longPressGestureRecognizer.numberOfTapsRequired = 0;
        
        self.longPressGestureRecognizer.allowableMovement = 10.0;
        
        [self.customButton addGestureRecognizer:self.longPressGestureRecognizer];
     
        self.prolongedPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self motion:@selector(prolongedPress:)];
        
        self.prolongedPressGestureRecognizer.delegate = self;
        
        self.prolongedPressGestureRecognizer.minimumPressDuration = 1.5;
        
        self.prolongedPressGestureRecognizer.numberOfTouchesRequired = 1;
        
        self.prolongedPressGestureRecognizer.numberOfTapsRequired = 0;
        
        self.prolongedPressGestureRecognizer.allowableMovement = 10.0;
        
        [self.customButton addGestureRecognizer:self.prolongedPressGestureRecognizer];

Situations:

When the primary one fires I would like for one thing to occur.

When the second fires I would like for the context menu to point out.

Presently, I’ve no method to do that.

Options:

  1. Is it doable to delay the time it takes for the context menu to look? I am positive there is a lengthy press gesture recognizer internally that reveals the menu. Can I modify this gesture recognizer?

2. Is it doable to point out the menu programmatically?

        NSMutableArray* actions = [[NSMutableArray alloc] init];

        [actions addObject:[UIAction actionWithTitle:@"Edit"
                                               image:nil
                                          identifier:nil
                                             handler:^(__kindof UIAction* _Nonnull action) {
            
            // ...
        }]];

        UIMenu* menu =
        [UIMenu menuWithTitle:@""
                     children:actions];
        
        self.customButton.menu = menu;



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments