MessageKitで画像の非同期読み込みをやりたかったのだが、マニュアルにやり方かいてなかったのでメモ。
答えはここにあった。
cf: Async Images with KingFisher with configureMediaMessageImageView #752
今回私はNukeを使っていたのでNukeでこんな感じで書いてみた。
class ViewController: MessagesViewController, MessagesDisplayDelegate { func configureMediaMessageImageView(_ imageView: UIImageView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) { switch message.kind { // 画像のチャットのときだけ非同期読み込みを行う case .photo(let photoItem): /// if we don't have a url, that means it's simply a pending message guard let url = photoItem.url else { return } imageView.contentMode = .scaleAspectFit // 読み込むまでの画像を設定 let options = ImageLoadingOptions(placeholder: #imageLiteral(resourceName: "IconImage")) Nuke.loadImage(with: url, options: options, into: imageView) default: break } } }
これでいい画像ビューワーライフが送れる
こんにちは。virapture…
View Comments
Thank you very much for sharing, I learned a lot from your article. Very cool. Thanks. nimabi
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.com/bg/join?ref=T7KCZASX
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.com/fr/join?ref=OMM3XK51
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.info/zh-TC/join?ref=53551167