我正在使用UIImagePickerController让我的应用程序的用户拍照或使用相机胶卷。当我测试使用相机选项时,图像始终旋转。但是当我尝试使用相机胶卷时,这种情况从未发生过。这是我用于UIImagePickerController的代码。
func photoLibary() {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.mediaTypes = [kUTTypeImage as NSString]
imagePicker.allowsEditing = false
self.view?.window?.rootViewController?.presentViewController(imagePicker, animated: true, completion: nil)
}
func camera() {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.mediaTypes = [kUTTypeImage as NSString]
imagePicker.allowsEditing = false
self.view?.window?.rootViewController?.presentViewController(imagePicker, animated: true, completion: nil)
}
func choosePhoto() {
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
actionSheet.addAction(UIAlertAction(title: "Take Photo", style: UIAlertActionStyle.Default, handler: { (alert:UIAlertAction!) -> Void in
self.camera()
}))
actionSheet.addAction(UIAlertAction(title: "Camera Roll", style: UIAlertActionStyle.Default, handler: { (alert:UIAlertAction!) -> Void in
self.photoLibary()
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.view!.window!.rootViewController!.presentViewController(actionSheet, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
let image:UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
image.texture = SKTexture(image: image)
picker.dismissViewControllerAnimated(true, completion: nil)
}