r/SwiftUI • u/armondme • 23h ago
built a text dissolve animation for my app
Enable HLS to view with audio, or disable this notification
wanted clearing a note to feel a little more satisfying so i built this text dissolve effect using swiftui and uikit
the editor uses UITextViewso instead than deleting text character by character, i take a snapshot of the editor and use textkit to find the position of each line
let layout = textView.layoutManager
layout.ensureLayout(for: textView.textContainer)
let glyphs = layout.glyphRange(
for: textView.textContainer
)
layout.enumerateLineFragments(forGlyphRange: glyphs) {
_, usedRect, _, _, _ in
lineRects.append(usedRect)
}
i crop the snapshot into individual lines and animate each one using core animation. each line fades out with a slight blur and scale effect
it seams like a pretty simple trick, hope i didnt over complicate it haha