【发布时间】:2023-03-07 18:24:01
【问题描述】:
我正在使用 UIImagePickerController 使用相机捕捉图像。我的应用支持的方向是纵向。我看到 iPhone 5 的奇怪行为。我正在使用 Xcode 7 和 swift 2.0。 iPhone 5 操作系统版本为 8.4。我的应用的部署目标是 8.0。
问题是。 1. 对于 iPhone 5,拍摄图像后,图像会以拍摄图像的相应模式显示。但是在我按下“使用照片”标准选项后,当图像显示在 UIImageView 上时,图像会自动向左旋转。不知道为什么。如果我从照片库中选择图像,图像不会旋转。我不想旋转图像。 我看到了类似的帖子,有更好的解释和实际图像,但没有得到回答。 UIImageView rotates image with retina 4 iPhone simulator but not retina 3.5/regular simulator 我尝试了这篇帖子中几乎所有的快速解决方案:iOS UIImagePickerController result image orientation after upload 和其他帖子,但似乎没有任何效果。我使用了 shouldAutorotate()、sFunc_imageFixOrientation(),并从这篇文章中添加了扩展。
- 另外,对于这两款设备,在按下“使用照片”选项后,上传图片大约需要 10 秒。能不能做得更快。
这是我的代码:
func openCamera() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
dispatch_async(dispatch_get_main_queue(), {
let imagePicker = UIImagePickerController();
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.allowsEditing = false;
imagePicker.delegate = self;
imagePicker.modalPresentationStyle = .FormSheet
self.presentViewController(imagePicker, animated: true, completion: nil);
});
}
}
func openGallary() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary;
imagePicker.allowsEditing = true
self.presentViewController(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
profileImage?.image = image
self.dismissViewControllerAnimated(true, completion: nil);
}
【问题讨论】:
标签: swift uiimagepickercontroller uiimageorientation