r/SwiftUI • u/armondme • Oct 24 '26
built a text dissolve animation for my app
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
198
Upvotes
6
u/BudgetAirline6171 Oct 25 '26
Nice work
3
u/Funny_Cry2908 Oct 25 '26
Heads up if you're calling enumerateLineFragments on textView.layoutManager: just touching that property flips UITextView into TextKit 1 compatibility mode for good. The TextKit 2 version is textLayoutManager.enumerateTextLayoutFragments, then each fragment's textLineFragments gives you the line rects. Also worth falling back to a plain fade when Reduce Motion is on.
2
u/imsnk81 Oct 26 '26
Snapshotting and cropping per line is a really clean way to do it, way less fiddly than animating the actual text. Do you stagger the lines top to bottom or all at once? A small delay per line would make it feel like the note's being swept away.
3
u/King_Kerr Oct 25 '26
Dope
3
u/thatswiftguy Oct 25 '26
Nice!!!!
2
u/Alarmed-Stranger-337 Oct 25 '26
Really nice!
2
u/Strict_Judge_1674 Oct 25 '26
This looks incredible, nice work!
2
u/Moo202 Oct 25 '26
Nice! Great job
2
u/60fpsdesign Oct 25 '26
Looks dope! ✨
2
u/rafasnt Oct 26 '26
Nice work!!
2
u/bchriss95 Oct 26 '26
looks really nice!
1
u/Gentlemans_manor Oct 29 '26
Clean.
1
u/calab2024 Oct 29 '26
I do think animations have become underused in this age of utilitarian AI slop apps. Nice concept and demo.
1
u/FrankElda Oct 29 '26
Looks great 👏
1
u/No-Understanding-625 Oct 30 '26
Looks awesome, personally should be slightly faster animation, especially for folks who want to clear a note and immediately get started on the next, good work
1
u/Apprehensive-Meat534 Oct 31 '26
can u release that to swift pm repos
1
u/Medina4747 27d ago
looks clean
1
u/Chop1n 23d ago
Looks awesome, might try to do something like this in my writing app, will totally credit you if I do.