chore: code format

This commit is contained in:
sunxiaojian 2021-03-02 16:27:58 +08:00
parent ea511c153f
commit 211f5dd0e4
1 changed files with 19 additions and 20 deletions

View File

@ -5,31 +5,30 @@
// Created by sxiaojian on 2021/3/2. // Created by sxiaojian on 2021/3/2.
// //
import Foundation
import UIKit
import CropViewController import CropViewController
import Foundation
import PhotosUI import PhotosUI
extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerViewControllerDelegate, UINavigationControllerDelegate{ import UIKit
extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerViewControllerDelegate {
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
if let itemProvider = results.first?.itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) { guard let itemProvider = results.first?.itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) else {
picker.dismiss(animated: true, completion: {})
itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in return
guard let self = self, let image = image as? UIImage else { return } }
DispatchQueue.main.async { itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, _ in
let cropController = CropViewController(croppingStyle: .default, image: image) guard let self = self, let image = image as? UIImage else { return }
cropController.delegate = self DispatchQueue.main.async {
self.image = image let cropController = CropViewController(croppingStyle: .default, image: image)
picker.dismiss(animated: true, completion: { cropController.delegate = self
self.present(cropController, animated: true, completion: nil) self.image = image
}) picker.dismiss(animated: true, completion: {
} self.present(cropController, animated: true, completion: nil)
})
} }
} else {
picker.dismiss(animated: true, completion: {
})
} }
} }
public func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) { public func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) {
self.image = image self.image = image
self.photoButton.setImage(image, for: .normal) self.photoButton.setImage(image, for: .normal)
@ -39,7 +38,7 @@ extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerVi
@objc func avatarButtonPressed(_ sender: UIButton) { @objc func avatarButtonPressed(_ sender: UIButton) {
var configuration = PHPickerConfiguration() var configuration = PHPickerConfiguration()
configuration.filter = .images configuration.filter = .images
let imagePicker = PHPickerViewController(configuration: configuration) let imagePicker = PHPickerViewController(configuration: configuration)
imagePicker.delegate = self imagePicker.delegate = self
self.present(imagePicker, animated: true, completion: nil) self.present(imagePicker, animated: true, completion: nil)