From 211f5dd0e459a994a5012ea899b2d8c998e314a3 Mon Sep 17 00:00:00 2001 From: sunxiaojian Date: Tue, 2 Mar 2021 16:27:58 +0800 Subject: [PATCH] chore: code format --- ...astodonRegisterViewController+Avatar.swift | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift index b25b402df..67bd2629e 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController+Avatar.swift @@ -5,31 +5,30 @@ // Created by sxiaojian on 2021/3/2. // -import Foundation -import UIKit import CropViewController +import Foundation import PhotosUI -extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerViewControllerDelegate, UINavigationControllerDelegate{ +import UIKit + +extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerViewControllerDelegate { func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { - if let itemProvider = results.first?.itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) { - - itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in - guard let self = self, let image = image as? UIImage else { return } - DispatchQueue.main.async { - let cropController = CropViewController(croppingStyle: .default, image: image) - cropController.delegate = self - self.image = image - picker.dismiss(animated: true, completion: { - self.present(cropController, animated: true, completion: nil) - }) - } + guard let itemProvider = results.first?.itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) else { + picker.dismiss(animated: true, completion: {}) + return + } + itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, _ in + guard let self = self, let image = image as? UIImage else { return } + DispatchQueue.main.async { + let cropController = CropViewController(croppingStyle: .default, image: image) + cropController.delegate = self + 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) { self.image = image self.photoButton.setImage(image, for: .normal) @@ -39,7 +38,7 @@ extension MastodonRegisterViewController: CropViewControllerDelegate, PHPickerVi @objc func avatarButtonPressed(_ sender: UIButton) { var configuration = PHPickerConfiguration() configuration.filter = .images - + let imagePicker = PHPickerViewController(configuration: configuration) imagePicker.delegate = self self.present(imagePicker, animated: true, completion: nil)