feat: 添加云盘与消息中心功能
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
//
|
||||
// CloudDrivePreviewViewController.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import AVKit
|
||||
import Kingfisher
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 云盘文件预览页,黑底展示图片或视频。
|
||||
final class CloudDrivePreviewViewController: BaseViewController {
|
||||
private let file: CloudFile
|
||||
private let imageView = UIImageView()
|
||||
private var playerViewController: AVPlayerViewController?
|
||||
|
||||
/// 初始化预览页。
|
||||
init(file: CloudFile) {
|
||||
self.file = file
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = ""
|
||||
navigationController?.navigationBar.tintColor = .white
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = .black
|
||||
if file.isVideo {
|
||||
setupVideo()
|
||||
} else {
|
||||
setupImage()
|
||||
}
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
navigationController?.navigationBar.tintColor = AppColor.primary
|
||||
playerViewController?.player?.pause()
|
||||
}
|
||||
|
||||
private func setupImage() {
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
imageView.backgroundColor = .black
|
||||
view.addSubview(imageView)
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.edges.equalTo(view.safeAreaLayoutGuide)
|
||||
}
|
||||
if let url = URL(string: file.fileUrl) {
|
||||
imageView.kf.setImage(with: url)
|
||||
}
|
||||
}
|
||||
|
||||
private func setupVideo() {
|
||||
guard let url = URL(string: file.fileUrl) else { return }
|
||||
let player = AVPlayer(url: url)
|
||||
let controller = AVPlayerViewController()
|
||||
controller.player = player
|
||||
controller.view.backgroundColor = .black
|
||||
addChild(controller)
|
||||
view.addSubview(controller.view)
|
||||
controller.view.snp.makeConstraints { make in
|
||||
make.edges.equalTo(view.safeAreaLayoutGuide)
|
||||
}
|
||||
controller.didMove(toParent: self)
|
||||
playerViewController = controller
|
||||
player.play()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user