Created
July 7, 2016 08:07
-
-
Save vinamelody/015c24ac72b73f11edadf1481905a112 to your computer and use it in GitHub Desktop.
Swift: Take photo button action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try presenting using something other than over current context