Skip to content

Instantly share code, notes, and snippets.

@vinamelody
Created July 7, 2016 08:07
Show Gist options
  • Save vinamelody/015c24ac72b73f11edadf1481905a112 to your computer and use it in GitHub Desktop.
Save vinamelody/015c24ac72b73f11edadf1481905a112 to your computer and use it in GitHub Desktop.
Swift: Take photo button action
@IBAction func takePhoto(sender: UIButton) {
let imagePicker: UIImagePickerController! = UIImagePickerController()
imagePicker.delegate = self
if (UIImagePickerController.isSourceTypeAvailable(.Camera)) {
if UIImagePickerController.availableCaptureModesForCameraDevice(.Front) != nil {
imagePicker.allowsEditing = false
imagePicker.sourceType = .Camera
imagePicker.cameraCaptureMode = .Photo
imagePicker.cameraDevice = .Front
imagePicker.modalPresentationStyle = .OverCurrentContext
presentViewController(imagePicker, animated: true, completion: {})
} else {
print("Camera not found")
}
} else {
print("Application cannot access the camera.")
}
}
@echoz
Copy link

echoz commented Jul 8, 2016

Try presenting using something other than over current context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment