带有IOS9的iPad上的UIImagePickerController [英] UIImagePickerController on iPad with IOS9
问题描述
从iOS 9和Xcode 7开始,我无法再在iPad(设备和模拟器)上实现UIImagePickerController。以下代码适用于iPad,但仅适用于iOS 9.使用iOS 9+时,显示的图像(在UIImagePickerController被取消后)是所选图像的错误版本。没有重新调整大小或裁剪最终图像只是原始图像的右上角??另外一个问题 - 如果imagePicker.allowsEditing = false,你无法从PhotoLibrary中选择图像?
Since iOS 9 and Xcode 7 I am no longer able to implemet a UIImagePickerController on an iPad (both device and simulator). The code below works on the iPad but only prior to iOS 9. When using iOS 9+ the presented image (after the UIImagePickerController is dismissed) is an incorrect version of the selected image. Without re-sizing or cropping the final image is only the top right corner of the original image ?? Plus another problem - If imagePicker.allowsEditing = false, you are unable to select images from the PhotoLibrary ??
@IBAction func photoButton(sender: AnyObject) {
imagePicker.allowsEditing = true
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: false, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
self.imageView.image = pickedImage
dismissViewControllerAnimated(true, completion: { () -> Void in
})
}
以下是UIImagePickerController中显示的所选图像的示例。 (注意所选图像如何呈现非常小而不像以前那样呈现屏幕的完整尺寸/宽度)
Heres an example of a selected image presented in a UIImagePickerController. (notice how the selected image is presented very small and not full size/width of screen as before)
在UIImagePickerController中选择使用按钮后,最终图像仅位于原始图像的右上角。我做错了什么或者UIImagePickerController在iOS 9上坏了?
After selecting the use button within the UIImagePickerController the final image is only the top right of the original image. What am I doing wrong or is UIImagePickerController broken on iOS 9 ?
推荐答案
这是Apple的错误:
http://openradar.appspot.com/radar ?id = 5032957332946944
This is a bug from Apple: http://openradar.appspot.com/radar?id=5032957332946944
当前糟糕的解决方法:
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
imagePicker.allowsEditing = false
} else {
imagePicker.allowsEditing = true
}
Swift 3.0:
Swift 3.0:
if UIDevice.current.userInterfaceIdiom == .pad {
}
这篇关于带有IOS9的iPad上的UIImagePickerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!