How can we animate a single character within a string? ie: I have the string: "Hey ". I would like to animate the emoji by setting it to rotate back and forth so it looks like it's waving.
To detect the emoji, I'm using:
extension String {
// Not needed anymore in swift 4.2 and later, using `.count` will give you the correct result
var glyphCount: Int {
let richText = NSAttributedString(string: self)
let line = CTLineCreateWithAttributedString(richText)
return CTLineGetGlyphCount(line)
}
var isSingleEmoji: Bool {
return glyphCount == 1 && containsEmoji
}
var containsEmoji: Bool {
return unicodeScalars.contains { $0.isEmoji }
}
I'm using the emoji code here: Find out if Character in String is emoji?.
I'm unsure how to set up the animation