ios - Animated UIImage in UITextView with TextKit -


i have uiimage contains multiple image frames , duration sliced animated gif file. if load image in uiwebview animate expected, want use uitextview instead. obvious choice use textkit custom nslayoutmanger , many custom nsattributedstring attributes achieve various drawing effects. have single uitextview i'd give nsattributedstring contains nstextattachments of images need display inline. it's working fine except when load 1 of these animated uiimages, not animate through frames. thoughts on how accomplish this? i've come theoretical option:

  1. for each animated image add custom defined attribute
  2. when layout manager goes draw backgrounds, iterate attribute locate positions of attachment.
  3. callback text view create uiimageviews animated image, add subview, , call startanimating

i have yet try this, it's hacky. i'm wondering if there's better option.

in summary: want animate uiimage inside uitextview via nstextattachment inside nsattributedstring without necessity uiimageview objects. can ignore fact done uiwebview. uiimage has properties (images, duration) setting animated frames, have configured. if assign uiimageview animates, if set nstextattachment, no animation.

i appreciate feedback. thanks!

i think behaviour because uitextview doesn't display attachments using uiimageview subviews. when observe view hierarchy , without nstextattachments added uitextview, don't see new views (you can observe view hierarchy using view debugging in xcode, or saying [[[uiapplication sharedapplication] keywindow] recursivedescription]). presumably, uitextview draws it's attachments directly.

that said, 1 way can think of include animatable attachment create animated uiimageview subview of uitextview, place nslayoutmanager places nstextattachment, , scroll whenever uitextview scrolls. can rectangle of nstextattachment nslayoutmanager calling boundingrectforglyphrange:intextcontainer: (possibly in layoutmanager:didcompletelayoutfortextcontainer:atend:).


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -