I want to implement quick actions like native Files application, on long press any item quick action view appears. Is there anything available in iOS to achieve it. I have attached some screenshots for better understanding. I know about Quick actions on home screen, I only want to achieve such thing inside my App not on AppIcon tap.
Asked
Active
Viewed 282 times
-1
-
1It's called a _menu_ (or _context menu_). See https://developer.apple.com/documentation/uikit/uicontrol/adding_context_menus_in_your_app – matt Apr 19 '22 at 07:46
1 Answers
0
It's called a context menu. See https://developer.apple.com/documentation/uikit/uicontrol/adding_context_menus_in_your_app
For Tableview you can implement like below. when long press it will be invoked
- (nullable UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point API_AVAILABLE(ios(13.0)) { UIContextMenuConfiguration *config = [UIContextMenuConfiguration configurationWithIdentifier:@"MenuControls" previewProvider:nil actionProvider:^UIMenu * _Nullable(NSArray<UIMenuElement *> * _Nonnull suggestedActions) { NSMutableArray *actions = [[NSMutableArray alloc] init]; [actions addObject:[UIAction actionWithTitle:@"Copy" image:[UIImage systemImageNamed:@"doc.on.doc.fill"] identifier:nil handler:^(__kindof UIAction * _Nonnull action) { // Do corresponding action based on menu item [UIPasteboard generalPasteboard].string = @"Sample Data"; }]]; if (@available(iOS 14.0, *)) { UIMenu *menu = [UIMenu menuWithChildren:actions]; return menu; } else { // Fallback on earlier versions UIMenu *menu = [UIMenu menuWithTitle:@"Actions" children:actions]; return menu; } }]; return config; }
For collection view same can be achieved by using below method
- (nullable UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionView contextMenuConfigurationForItemAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(watchos, tvOS);

Arasuvel
- 2,971
- 1
- 25
- 40