iOS 13.4(2020 年 3 月)更新:
UIPointerInteraction
将鼠标悬停在链接上时也会发生这种情况。
当用户长按链接时,我有一个显示富文本并显示 iOS 13 上下文菜单的视图。当用户开始长按时,我希望能够仅突出显示链接而不是整个视图。
为此,我提供了一个UITargetedPreview
对象,其中包含要在视图中突出显示的每行UIPreviewParameters
的s。这正确地突出了链接,但也有隐藏视图其余部分的不良副作用。CGRect
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)
return UITargetedPreview(view: /* the rich text view */, parameters: parameters)
}
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, previewForDismissingMenuWithConfiguration 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)
return UITargetedPreview(view: /* the rich text view */, parameters: parameters)
}
UITargetedPreview
我在and的文档中找不到任何内容UIPreviewParameters
,所以有人知道如何做到这一点吗?