mirror of
https://github.com/metabolist/metatext.git
synced 2025-02-19 15:26:17 +00:00
Fix animated text attachment positioning
This commit is contained in:
parent
8bf5a757ea
commit
6f77983d8d
2 changed files with 9 additions and 3 deletions
|
@ -45,10 +45,8 @@ final class AnimatedAttachmentLabel: UILabel, EmojiInsertable {
|
||||||
else { return }
|
else { return }
|
||||||
|
|
||||||
animatedAttachment.imageView.frame = imageBounds
|
animatedAttachment.imageView.frame = imageBounds
|
||||||
|
|
||||||
animatedAttachment.imageView.image = animatedAttachment.image
|
animatedAttachment.imageView.image = animatedAttachment.image
|
||||||
animatedAttachment.imageView.contentMode = .scaleAspectFit
|
animatedAttachment.imageView.contentMode = .scaleAspectFit
|
||||||
animatedAttachment.imageView.center.y = center.y
|
|
||||||
animatedAttachment.imageView.sd_setImage(with: animatedAttachment.imageURL)
|
animatedAttachment.imageView.sd_setImage(with: animatedAttachment.imageURL)
|
||||||
|
|
||||||
if animatedAttachment.imageView.superview != self {
|
if animatedAttachment.imageView.superview != self {
|
||||||
|
|
|
@ -11,7 +11,15 @@ final class AnimatedTextAttachment: NSTextAttachment {
|
||||||
override func image(forBounds imageBounds: CGRect,
|
override func image(forBounds imageBounds: CGRect,
|
||||||
textContainer: NSTextContainer?,
|
textContainer: NSTextContainer?,
|
||||||
characterIndex charIndex: Int) -> UIImage? {
|
characterIndex charIndex: Int) -> UIImage? {
|
||||||
|
if let textContainer = textContainer,
|
||||||
|
let textContainerImageBounds = textContainer.layoutManager?.boundingRect(
|
||||||
|
forGlyphRange: NSRange(location: charIndex, length: 1),
|
||||||
|
in: textContainer),
|
||||||
|
textContainerImageBounds != .zero {
|
||||||
|
self.imageBounds = textContainerImageBounds
|
||||||
|
} else {
|
||||||
self.imageBounds = imageBounds
|
self.imageBounds = imageBounds
|
||||||
|
}
|
||||||
|
|
||||||
return nil // rendered by AnimatingLayoutManager or AnimatedAttachmentLabel
|
return nil // rendered by AnimatingLayoutManager or AnimatedAttachmentLabel
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue