55 lines
1.4 KiB
Swift
55 lines
1.4 KiB
Swift
//
|
|
// ImageCropVC.swift
|
|
// QuickLocation
|
|
//
|
|
|
|
import UIKit
|
|
|
|
final class ImageCropVC: BaseViewController {
|
|
|
|
override var isNavigationBarHidden: Bool { true }
|
|
override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent }
|
|
|
|
var onConfirm: ((UIImage) -> Void)?
|
|
var onCancel: (() -> Void)?
|
|
|
|
private let image: UIImage
|
|
private var rootView: ImageCropView!
|
|
|
|
init(image: UIImage) {
|
|
self.image = image
|
|
super.init(nibName: nil, bundle: nil)
|
|
modalPresentationStyle = .fullScreen
|
|
modalPresentationCapturesStatusBarAppearance = true
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func loadView() {
|
|
rootView = ImageCropView(frame: UIScreen.main.bounds)
|
|
view = rootView
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
rootView.setImage(image)
|
|
rootView.onCancel = { [weak self] in
|
|
self?.dismiss(animated: true) {
|
|
self?.onCancel?()
|
|
}
|
|
}
|
|
rootView.onConfirm = { [weak self] in
|
|
guard let self else { return }
|
|
guard let cropped = self.rootView.croppedImage() else {
|
|
DLToast.show(text: "图片处理失败")
|
|
return
|
|
}
|
|
self.dismiss(animated: true) {
|
|
self.onConfirm?(cropped)
|
|
}
|
|
}
|
|
}
|
|
}
|