UITextView should support view-based attachments

Originator:douglashill
Number:rdar://41398179 Date Originated:23-Jun-2018 04:09 pm
Status:Open Resolved:
Product:iOS + SDK Product Version:12.0
Classification:Feature (New) Reproducible:Always
 
Summary:
UITextView has a generic attachment system that is currently only used for images. It would be useful to be able to add custom views mixed in with the text, as view-based attachments.

My primary use-case is actually displaying images in UIImageView. The reasons for not using image attachments are

1) UITextView draws its content, and drawing large images takes too long resulting in dropping frames. UIImageView is very well optimised so does not have this problem.
2) I want to add custom interaction with the images, such as pinch to zoom.

View-based attachments would also be useful having any type of interactive widget mixed in with text content (like books made in iBooks Author, but native instead of web-based).

Steps to Reproduce:
Look for some kind of API for view-based attachments in UITextView.

Expected Results:
Find some kind of API for view-based attachments.

Actual Results:
No such API for view-based attachments.

Version:
12.0

Notes:
My current solution to this problem is to create a subclass of NSTextAttachment that specifies a size and add these to the text storage with no image set. Then implement layoutManager:didCompleteLayoutForTextContainer:atEnd: and find all these attachments in the container and add views to the view hierarchy at the attachment positions. This is okay, but a bit messy and Radar 41398146 is a problem when tapping near (but not directly on) an image as it highlights the fake attachment.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!