同步相册云盘界面并完善相关交互
This commit is contained in:
@ -8,13 +8,17 @@ import Kingfisher
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 云盘文件预览页,黑底展示图片或视频。
|
||||
/// 云盘文件预览页,严格对齐 Android 黑底预览并保留 iOS 原生视频控制层。
|
||||
final class CloudDrivePreviewViewController: BaseViewController {
|
||||
private let file: CloudFile
|
||||
private let imageView = UIImageView()
|
||||
private var playerViewController: AVPlayerViewController?
|
||||
private var previousStandardAppearance: UINavigationBarAppearance?
|
||||
private var previousScrollEdgeAppearance: UINavigationBarAppearance?
|
||||
private var previousCompactAppearance: UINavigationBarAppearance?
|
||||
private var previousTintColor: UIColor?
|
||||
|
||||
/// 初始化预览页。
|
||||
/// 初始化云盘文件预览页。
|
||||
init(file: CloudFile) {
|
||||
self.file = file
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
@ -25,9 +29,23 @@ final class CloudDrivePreviewViewController: BaseViewController {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override var preferredStatusBarStyle: UIStatusBarStyle {
|
||||
.lightContent
|
||||
}
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = ""
|
||||
navigationController?.navigationBar.tintColor = .white
|
||||
navigationItem.titleView = UIView()
|
||||
navigationItem.hidesBackButton = true
|
||||
let backButton = UIButton(type: .system)
|
||||
backButton.setImage(
|
||||
UIImage(systemName: "chevron.left")?.withConfiguration(UIImage.SymbolConfiguration(pointSize: 20, weight: .medium)),
|
||||
for: .normal
|
||||
)
|
||||
backButton.tintColor = .white
|
||||
backButton.accessibilityLabel = "返回"
|
||||
backButton.addTarget(self, action: #selector(backTapped), for: .touchUpInside)
|
||||
backButton.snp.makeConstraints { make in make.width.height.equalTo(44) }
|
||||
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
@ -39,37 +57,71 @@ final class CloudDrivePreviewViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
applyTransparentNavigationBar()
|
||||
setNeedsStatusBarAppearanceUpdate()
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
navigationController?.navigationBar.tintColor = AppColor.primary
|
||||
restoreNavigationBar()
|
||||
playerViewController?.player?.pause()
|
||||
}
|
||||
|
||||
private func setupImage() {
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
imageView.backgroundColor = .black
|
||||
imageView.accessibilityLabel = file.name
|
||||
view.addSubview(imageView)
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.edges.equalTo(view.safeAreaLayoutGuide)
|
||||
}
|
||||
if let url = URL(string: file.fileUrl) {
|
||||
imageView.snp.makeConstraints { make in make.edges.equalTo(view.safeAreaLayoutGuide) }
|
||||
if let url = URL(string: file.fileUrl), !file.fileUrl.isEmpty {
|
||||
imageView.kf.setImage(with: url)
|
||||
}
|
||||
}
|
||||
|
||||
private func setupVideo() {
|
||||
guard let url = URL(string: file.fileUrl) else { return }
|
||||
guard let url = URL(string: file.fileUrl), !file.fileUrl.isEmpty 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.view.snp.makeConstraints { make in make.edges.equalTo(view.safeAreaLayoutGuide) }
|
||||
controller.didMove(toParent: self)
|
||||
playerViewController = controller
|
||||
player.play()
|
||||
}
|
||||
|
||||
private func applyTransparentNavigationBar() {
|
||||
guard let navigationBar = navigationController?.navigationBar else { return }
|
||||
previousStandardAppearance = navigationBar.standardAppearance
|
||||
previousScrollEdgeAppearance = navigationBar.scrollEdgeAppearance
|
||||
previousCompactAppearance = navigationBar.compactAppearance
|
||||
previousTintColor = navigationBar.tintColor
|
||||
|
||||
let appearance = UINavigationBarAppearance()
|
||||
appearance.configureWithTransparentBackground()
|
||||
appearance.backgroundColor = .clear
|
||||
appearance.shadowColor = .clear
|
||||
navigationBar.standardAppearance = appearance
|
||||
navigationBar.scrollEdgeAppearance = appearance
|
||||
navigationBar.compactAppearance = appearance
|
||||
navigationBar.tintColor = .white
|
||||
}
|
||||
|
||||
private func restoreNavigationBar() {
|
||||
guard let navigationBar = navigationController?.navigationBar else { return }
|
||||
if let previousStandardAppearance {
|
||||
navigationBar.standardAppearance = previousStandardAppearance
|
||||
}
|
||||
navigationBar.scrollEdgeAppearance = previousScrollEdgeAppearance
|
||||
navigationBar.compactAppearance = previousCompactAppearance
|
||||
navigationBar.tintColor = previousTintColor
|
||||
}
|
||||
|
||||
@objc private func backTapped() {
|
||||
navigationController?.popViewController(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user