Skip to content

Commit

Permalink
优化:编辑器中显示gif
Browse files Browse the repository at this point in the history
  • Loading branch information
rztime committed Oct 12, 2023
1 parent 573e309 commit c7c6dfb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Example/RZRichTextView/HowToUseDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public extension RZRichTextViewModel {
vc.currentIndex = index

let models = allattachments.compactMap { info -> TZAssetModel? in
var i: UInt = 0
var i: UInt = 2
switch info.type {
case .image:break
case .video: i = 3
Expand Down
46 changes: 37 additions & 9 deletions RZRichTextView/Classes/RZAttachmentInfoLayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import UIKit
import QuicklySwift

import Kingfisher
import Photos
/// 操作
public enum RZAttachmentOperation {
case none
Expand Down Expand Up @@ -40,17 +41,37 @@ open class RZAttachmentInfoLayerView: UIView, RZAttachmentInfoLayerProtocol {
guard let info = info else { return }
imageContent.isHidden = info.type == .audio
audioContent.isHidden = info.type != .audio

self.playBtn.isHidden = info.type != .video
switch info.type {
case .image, .video:
self.playBtn.isHidden = info.type == .image
case .image:
if let asset = info.asset {
let option = PHImageRequestOptions.init()
option.isNetworkAccessAllowed = true
option.resizeMode = .fast
option.deliveryMode = .highQualityFormat
PHImageManager.default().requestImageData(for: asset, options: option) { [weak self] data, _, _, _ in
if let imageData = data {
self?.imageView.kf.setImage(with: .provider(RawImageDataProvider(data: imageData, cacheKey: asset.localIdentifier))) { [weak self] _ in
self?.updateImageViewSize()
}
}
}
} else if let url = info.src {
self.imageView.kf.setImage(with: url.qtoURL, completionHandler: { [weak self] _ in
self?.updateImageViewSize()
})
} else {
info.imagePublish.subscribe({ [weak self] value in
guard let self = self else { return }
self.imageView.image = value
self.updateImageViewSize()
}, disposebag: dispose)
}
case .video:
info.imagePublish.subscribe({ [weak self] value in
guard let self = self else { return }
let size = value?.size ?? .init(width: 16.0, height: 9.0)
self.imageView.image = value
self.imageView.snp.makeConstraints { make in
make.height.equalTo(self.imageView.snp.width).multipliedBy(size.height / size.width)
}
self.updateImageViewSize()
}, disposebag: dispose)
case .audio:
if let path = info.path ?? info.src {
Expand Down Expand Up @@ -94,7 +115,7 @@ open class RZAttachmentInfoLayerView: UIView, RZAttachmentInfoLayerProtocol {
}
/// 图片视频相关view
// 显示的图片
public var imageView: UIImageView = .init().qcontentMode(.scaleAspectFill).qcornerRadius(3, true)
public var imageView: UIImageView = AnimatedImageView.init().qcontentMode(.scaleAspectFill).qcornerRadius(3, true)
/// 播放按钮
var playBtn: UIButton = .init(type: .custom).qimage(RZRichImage.imageWith("play")).qisUserInteractionEnabled(false)

Expand Down Expand Up @@ -214,4 +235,11 @@ open class RZAttachmentInfoLayerView: UIView, RZAttachmentInfoLayerProtocol {
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func updateImageViewSize() {
guard let image = self.imageView.image else { return }
let size = image.size
self.imageView.snp.makeConstraints { make in
make.height.equalTo(self.imageView.snp.width).multipliedBy(size.height / size.width)
}
}
}

0 comments on commit c7c6dfb

Please sign in to comment.