Search code examples
iosuitableviewanimationcontextmenuios13

Rounded corners for cell preview in the "insetGrouped" style (iOS 13)


I have found an annoying problem with UITableView when it is in the insetGrouped style. When implementing contextMenuConfigurationForRowAtIndexPath method, it allows to peek-and-pop cell preview with context actions. Everything works fine except the feature when iOS rounds corners of the preview window.

Corners are not rounded

But corners become rounded if the table in every other style (plain, for example). Also animation in plain mode is more "smooth" and preview is scaled down a little bit.

Corners are rounded

I also found out that iOS rounds top corners for the first cell and bottom corners for the last cell in the insetGrouped style.

Has anyone encountered similar behavior of UITableView?


Solution

  • You can rounded corner for cell by implement method 'previewForHighlightingContextMenuWithConfiguration'

    - (UITargetedPreview *)tableView:(UITableView *)tableView previewForHighlightingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration {
    NSIndexPath *index = (NSIndexPath *)configuration.identifier;
    SharedTableViewCell *cell = [self.tableView cellForRowAtIndexPath:index];
    
    UIPreviewParameters *parameters = [[UIPreviewParameters alloc] init];
    parameters.backgroundColor = UIColor.clearColor;
    parameters.visiblePath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds cornerRadius:10.0];
    UITargetedPreview *targetedPreview = [[UITargetedPreview alloc] initWithView:cell parameters:parameters];
    
    return targetedPreview;
    

    }