同步相册云盘界面并完善相关交互

This commit is contained in:
2026-07-10 17:15:15 +08:00
parent ab5220e460
commit ceca780ab3
13 changed files with 2269 additions and 532 deletions

View File

@ -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)
}
}