简体   繁体   中英

iOS 13 context menu: how to simply dismiss menu by tapping on preview?

I was able to implement the new context menu on a UITableView within a UIViewController following Kyle Bashour's excellent guide posted here:

https://kylebashour.com/posts/context-menu-guide

I don't want to implement any action when the user taps on the cell's preview. Instead, I simply want the menu to be dismissed and return to the table view.

This is the default behaviour, however the corresponding default animation for this is quite jumpy (expaning from the preview to cover the whole screen) as illustrated by running the sample app of the guide mentioned above:

Is there a way to implement the dismissal just to be the reverse animation of calling the context menu?

I just managed to find the solution.

Implementing the UITableViewDelegate willPerformPreviewActionForMenuWith function to set the animator's preferredCommitStyle to .dismiss does the trick.

func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
    animator.preferredCommitStyle = .dismiss
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM