metatext/Views/UIKit/AnimatedTextAttachment.swift

27 lines
915 B
Swift
Raw Normal View History

2021-02-22 07:10:34 +00:00
// Copyright © 2021 Metabolist. All rights reserved.
2021-02-22 23:59:33 +00:00
import SDWebImage
2021-02-22 07:10:34 +00:00
import UIKit
final class AnimatedTextAttachment: NSTextAttachment {
2021-02-22 23:59:33 +00:00
var imageURL: URL?
var imageView = SDAnimatedImageView()
2021-02-22 07:10:34 +00:00
var imageBounds: CGRect?
override func image(forBounds imageBounds: CGRect,
textContainer: NSTextContainer?,
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
}
2021-02-22 07:10:34 +00:00
return nil // rendered by AnimatingLayoutManager or AnimatedAttachmentLabel
}
}