gpt4 book ai didi

ios - 如何在我的应用程序中启用 "Photos"的编辑功能? [ swift 3]

转载 作者:行者123 更新时间:2023-12-03 19:23:50 25 4
gpt4 key购买 nike

问题:

即使设置为 true:

imagePicker.allowsEditing = true

仅显示裁剪功能,适用于 iPhone 尺寸的设备但不适用于 iPad 尺寸的设备(裁剪无法正常工作,它会返回错误的部分图片的一部分)。

enter image description here enter image description here

如何启用“照片”的编辑功能,以便用户可以使用此裁剪功能?

enter image description here

完成方法:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
isImageChanged = true

if UIDevice.current.userInterfaceIdiom == .pad {
//Code for iPad problem
pictureBox.image = image
}else{
pictureBox.contentMode = .scaleAspectFit
pictureBox.image = image
}

self.dismiss(animated: true, completion: nil)
}

调用ImagePickerController

let alertAction2 = UIAlertAction(title: "Library", style:UIAlertActionStyle.default){(UIAlertAction)-> Void in

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
if UIDevice.current.userInterfaceIdiom == .pad {
imagePicker.allowsEditing = true
} else if UIDevice.current.userInterfaceIdiom == .phone {
imagePicker.allowsEditing = true
}
self.present(imagePicker, animated: true, completion: nil)
}
}

最佳答案

我也遇到了同样的问题,有一个简单的解决方案。在 iPad 上使用 imagePickerController 时,您必须将其呈现为弹出窗 Eloquent 能正常进行编辑。 Source

下面是一些图像来说明编辑的工作原理。

enter image description here enter image description here

接下来,我们要解决 iPhone 上的 popOver 问题。弹出窗口无法在 iPhone 上显示,因此它只会显示占据整个屏幕的普通选择器。请注意,您可能还想检查您是否也有权访问照片库或相机。 (其代码位于上面提供的链接中。)

@IBAction func selectImagePressed(_ sender: Any) {
// check if we can access the library first? If no we need to ask again
picker.allowsEditing = true
picker.sourceType = .photoLibrary // can be camera or library

picker.modalPresentationStyle = .popover
picker.popoverPresentationController?.delegate = self as? UIPopoverPresentationControllerDelegate
picker.popoverPresentationController?.sourceView = view

let screenSize = UIScreen.main.bounds
let xLocation = (screenSize.width / 100) * 15
let yLocation = (screenSize.height / 2)
picker.popoverPresentationController?.sourceRect = CGRect(x: xLocation, y: yLocation, width: 0, height: 0)

present(picker, animated: true, completion: nil)
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
// Use editedImage Here
self.imageView.image = editedImage
nextButton.isHidden = false
}
else if let originalImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
// Use originalImage Here
self.imageView.image = originalImage
nextButton.isHidden = false
}
else {
if let vc = UIApplication.topViewController() {
Helper.showAlertMessage(vc: vc, title: "Image Error", message: "An error occured during image selection")
}
}

picker.dismiss(animated: true)
}

关于ios - 如何在我的应用程序中启用 "Photos"的编辑功能? [ swift 3],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42663773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com