iOS 13.4 更新(2020 年 3 月):
UIPointerInteraction将鼠标悬停在链接上时也会发生这种情况。
我有一个视图,当用户长按链接时,显示富文本并显示 iOS 13 上下文菜单。当用户开始长按时,我希望能够仅突出显示链接而不是整个视图。
为此,我提供了一个UITargetedPreview对象,其中包含UIPreviewParameters要在视图中CGRect突出显示的每行的 s 。UIContextMenuInteractionDelegate这正确地突出显示了链接,但也产生了隐藏视图其余部分的副作用。
这张图说明了这个问题:
请注意,虽然链接正确突出显示,但当长按链接然后释放时,视图的其余部分会闪烁。
将此与 Apple 自己的 Notes.app 中的行为进行比较:
请注意,长按链接时视图的其余部分不会消失。这在 Apple 的其他应用程序(例如 Safari)中也能按预期工作。
我UITargetedPreview通过以下方式向交互委托提供 s:
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, previewForHighlightingMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
guard let range = configuration.identifier as? NSRange else { return nil }
let lineRects: [NSValue] = // calculate appropriate rects for the range of text
let parameters = UIPreviewParameters(textLineRects: lineRects) …Run Code Online (Sandbox Code Playgroud) uikit ios swift uicontextmenuinteraction uipointerinteraction