到目前为止,我的相机工作正常,它以常规格式打开。但我希望唯一的选择是方格式。
到目前为止,这是我的代码。
@IBAction func takePhoto(sender: AnyObject) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .Camera
presentViewController(picker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
dismissViewControllerAnimated(true, completion: nil)
}
答案 0 :(得分:8)
我认为您不能使用UIImagePickerController以方格格式打开相机。你可以做的是将UIImagePickerController allowEditing设置为YES,然后从结果dict中使用键UIImagePickerControllerEditedImage然后你将得到平方图像,这样你就可以编码了。
@IBAction func takePhoto(sender: AnyObject) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .Camera
picker.allowsEditing = true
presentViewController(picker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
imageView.image = info[UIImagePickerControllerEditedImage] as? UIImage
dismissViewControllerAnimated(true, completion: nil)
}
此answer中提到了另一种方法。 您可以使用answer中的逻辑来编写swift中的代码。
但是如果你想查看细节并尝试做更多的事情,请看看
另请参阅apple sample。