[英]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:我能够按照 Kyle Bashour 在这里发布的优秀指南在 UIViewController 中的 UITableView 上实现新的上下文菜单:
https://kylebashour.com/posts/context-menu-guide 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.实现 UITableViewDelegate willPerformPreviewActionForMenuWith 函数将动画师的 preferredCommitStyle 设置为 .dismiss 就可以了。
func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
animator.preferredCommitStyle = .dismiss
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.