在 iOS 11 中拖放到 UITextView 上

Drag & drop on UITextView in iOS 11

我有一个可编辑的 UITextView。当我从该视图中拖动文本并将其放到自身上时,文本移动但未调用以下两个方法:

textView:shouldChangeTextInRange:replacementText:
textViewDidChange:

如果我想在文本移动后执行一些任务(例如,注册撤销或更新关联的 UIDocument),我该怎么办?提前谢谢你。

您可以将 textView 的 textDragDelegate 设置为自己并实现

- (void)textDraggableView:(UIView<UITextDraggable> *)textDraggableView dragSessionDidEnd:(id<UIDragSession>)session withOperation:(UIDropOperation)operation;

或 UITextDragDelegate 中的其他合适方法。

编辑:

实际上,在您的情况下,textDropDelegate 可能是更好的解决方案,因为新文本可能来自另一个应用程序。

那里似乎有一个合适的方法

- (void)textDroppableView:(UIView<UITextDroppable> *)textDroppableView willPerformDrop:(id<UITextDropRequest>)drop;