Visual_Novel_iOS/crush/Crush/Src/Components/Photo/PhotoBrowser/PhotoBrowserModel.swift

67 lines
1.9 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PhotoBrowserModel.swift
// Crush
//
// Created by Leon on 2025/7/26.
//
import UIKit
class PhotoBrowserModel:NSObject {
var image: UIImage?
var imageContentMode: UIView.ContentMode = .scaleAspectFill
var imageUrl: String?
var placeHolder: UIImage?
var sourceRect: CGRect = .zero
var tagInfo: Any?
var deleteTapBlock: ((PhotoBrowserModel, @escaping (Bool) -> Void) -> Void)?
var likeTapBlock: ((PhotoBrowserModel, @escaping (Bool) -> Void) -> Void)?
// MARK: 🚩
//
var aiAlbum: AlbumPhotoItem!
/// aiId
var aiId: Int?
var chatBackground: IMChatBackground?
// IM
var sessionModel: SessionBaseModel?
override init() {
sourceRect = .zero
imageContentMode = .scaleAspectFill
}
var computedSourceRect: CGRect {
if sourceRect == .zero {
if let image = image {
let width = image.size.width
let height = image.size.height
return CGRect(
x: UIScreen.main.bounds.width * 0.5 - width * 0.5,
y: UIScreen.main.bounds.height * 0.5 - height * 0.5,
width: width,
height: height
)
} else {
return CGRect(
x: UIScreen.main.bounds.width * 0.5 - 40,
y: UIScreen.main.bounds.height * 0.5 - 40,
width: 80,
height: 80
)
}
}
return sourceRect
}
static func getViewRectForScreen(with view: UIView) -> CGRect {
guard let window = UIApplication.shared.windows.first else { return .zero }
return view.superview?.convert(view.frame, to: window) ?? .zero
}
deinit {
print("EGPhotoBrowserModel dealloc")
}
}