Repository navigation
Detecting TapGesture on an ImageAttachment to execute associated action #179
martindufort
started this conversation in
Ideas
Replies: 4 comments 2 replies
|
As i mentioned here #178 i can intercept a tap gesture with an overlay. but this may be a dead end- without some ad hoc geometry there’s no way to know what was clicked |
0 replies
|
I asked perplexity.ai to give me some hints... Here's the result.
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
textView.addGestureRecognizer(tapRecognizer)
@objc func handleTap(_ recognizer: UITapGestureRecognizer) {
let textView = recognizer.view as! UITextView
let layoutManager = textView.layoutManager
var location = recognizer.location(in: textView)
location.x -= textView.textContainerInset.left
location.y -= textView.textContainerInset.top
let characterIndex = layoutManager.characterIndex(for: location, in: textView.textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
if characterIndex < textView.textStorage.length {
// Check if the character at this index has an attachment
let attributeValue = textView.attributedText.attribute(.attachment, at: characterIndex, effectiveRange: nil) as? NSTextAttachment
if let attachment = attributeValue {
// Handle the image change or any other attribute change
changeImageForAttachment(attachment)
}
}
}Now wondering if this AI hallucinations or not... |
0 replies
|
@martindufort, have you got a solution? im facing the same issue right now |
0 replies
|
There are sooo many things we should be able to do with image attachments, like resizing. But it's not trivial. Even the Notes app doesn't have good image handling. |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment




Uh oh!
There was an error while loading. Please reload this page.
I want to insert an ImageAttachment within the RichTextView that would respond to tap gestures.
So when the user taps the ImageAttachment, I need to be reported which ImageAttachment was tapped so I can take the appropriate action.
What would be the bets way to accomplish this?
All reactions