So far I have the camera working fine, it opens up in the regular format. But I want the only option to be square format.
Here is my code so far.
@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)
}
I don't think you can open camera in square format using UIImagePickerController. What you can do is set UIImagePickerController allowEditing to YES and from the result dict use the key UIImagePickerControllerEditedImage then you will have the squared image so you code becomes .
@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)
}
Another way around is mentioned in this answer . You can use the logic from answer to write the code in swift.
But if you want to look in details and try out doing some more have a look into
Also look at apple sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With