I am using UITextview in UITableview with copy and link detection for selection. Drag and drop is working without implementing Drag and drop feature on UITextview. So I want to disable UITextView drag and drop...
To disable the text dragging (where the text "pops out" and can be dragged across the screen), try the following:
if #available(iOS 11.0, *) {
textView.textDragInteraction?.isEnabled = false
}
I had a similar problem and have found a solution suitable for me.
So, I had a TableView
with a single TextView
inside every cell. I wanted to enable drag/drop for TableView
in order to be able to move cells. But when I was long-pressing a cell, I was actually pressing its TextView
, starting the drag session for it either. And whenever I tried to move that cell to a new position in TableView
, the app was trying to insert the text from that cell's TextView
to a new cell's TextView
, performing a "drag and drop text copy operation".
In order to disable such kind of interaction you can try the following:
extension YourTableViewCell: UITextDropDelegate {
func textDroppableView(_ textDroppableView: UIView & UITextDroppable, proposalForDrop drop: UITextDropRequest) -> UITextDropProposal {
return UITextDropProposal(operation: .cancel)
}
}
YourTableViewCell
a drop delegate for a TextView
(also in YourTableViewCell.swift)override func awakeFromNib() {
super.awakeFromNib()
YourTextView.textDropDelegate = self
}
Where YourTextView
is an outlet for your cell's text view
This will help your app to stop trying to insert text inside UITextView
in your TableView
.
Hope it helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With