简体   繁体   English

iOS 13 上下文菜单:如何通过点击预览简单地关闭菜单?

[英]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.

相关问题 关闭iOS上下文菜单 - Dismiss iOS context menu UIDocumentInteractionController 菜单不会关闭(React Native 0.61.5)iOS 13+ - UIDocumentInteractionController menu does not dismiss (React Native 0.61.5) iOS 13+ 如何以编程方式关闭上下文菜单(UIContextMenu)? - How to dismiss context menu (UIContextMenu) programmatically? 如何在取消时关闭滑动操作上下文菜单 - How to dismiss swipe action context menu on cancel 在 iPad 上的上下文菜单中点击预览不会对全屏视图控制器的演示进行动画处理 - Tapping preview in context menu on iPad doesn't animate presentation of full screen view controller 上下文菜单选择颜色和框架大小 Swift 5 iOS 13 - Context Menu selection color and frame size Swift 5 iOS 13 激活 iOS 13 上下文菜单时,如何防止 UIScrollView 放大一吨? - How do I prevent UIScrollView from zooming in a ton when activating an iOS 13 context menu? 如何像在Android中的上下文菜单一样在iOS中实现上下文菜单 - How to implement the context menu in iOS like the context menu in Android 关闭iOS原生MPVolumeView音频路由菜单 - Dismiss iOS native MPVolumeView audio route menu 上下文菜单预览提供程序以及情节提要选择 - Context menu preview provider with storyboard segues
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM