から編集した画像を返す:ので、私はそうのような設定でピッカーコントローラを持って、常にUIImagePickerController
func displayImagePickerButtonTapped() {
let myPickerController = UIImagePickerController()
myPickerController.delegate = self
myPickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary
myPickerController.allowsEditing = true
self.present(myPickerController, animated: true, completion: nil)
}
今myPickerController.allowsEditing = true
は編集することができます。しかし、編集は必須ではなく、この場合は贅沢なので、ユーザーは編集済みの画像ではなく元の画像を返すことができます。
編集した画像のみを選択できるようにするにはどうすればいいですか?毎回正方形の形に切り捨てられますか?ユーザーが写真を撮るか、フォトライブラリからいずれかを選択する際
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
dismiss(animated: true, completion: nil)
let cropVC = TOCropViewController(image: pickedImage)
cropVC.delegate = self
cropVC.aspectRatioPickerButtonHidden = true
cropVC.aspectRatioPreset = .presetSquare //Here you can set the ratio as 4.3, 4.2, square, etc
cropVC.aspectRatioLockEnabled = true //Here you lock the ratio
cropVC.resetAspectRatioEnabled = false
self.present(cropVC, animated: true, completion: nil)
}
}
func cropViewController(_ cropViewController: TOCropViewController, didCropTo image: UIImage, with cropRect: CGRect, angle: Int) {
self.yourImage.image = image
cropViewController.dismiss(animated: true, completion: nil)
}
ので、イメージピッカーを閉じて:
ユーザーが強制的に画像を編集することはできません。少なくとも 'UIImagePickerController'ではそうではありません。 – rmaddy