UIImagePickerController - How do I access the front facing camera by default?
UIImagePickerControllerCameraDeviceFront
is not a valid enum for the sourceType
property. The sourceType
property defines whether you're using the camera or the photo library. You need to set the cameraDevice
property instead.
Objective-C
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
Swift 2
imgPicker.sourceType = .Camera
imgPicker.cameraDevice = .Front
Swift 3
imgPicker.sourceType = .camera
imgPicker.cameraDevice = .front
Front facing camera in UIImagePickerController
You can flip the image from the source image use this
UIImage *flippedImage = [UIImage imageWithCGImage:picture.CGImage scale:picture.scale orientation:UIImageOrientationLeftMirrored];
Edit: Added swift code
let flippedImage = UIImage(CGImage: picture.CGImage, scale: picture.scale, orientation:.LeftMirrored)
iPad uiimagepickercontroller only front camera
This is a bit of a work around, but because there is no delegate for what you're looking for this will do the trick.
Sign up notifications from the PickerController in ViewDidLoad (In this case because you implement your own controls you may have to setup your own notification)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(retakeImage:)
name:@"_UIImagePickerControllerUserDidRejectItem" object:nil];
Then when the user chooses to retake the photo reassert the picker to use the front camera.
- (void)retakeImage:(NSNotification *)notification
{
self.pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
Hope this helps!
UIImagePickerController front camera show mirror image on preview view
finally, i can not solve this issue in UIImagePickerController
, but i solve this issue using AVFoundation
and CoreMotion
, you can see AVCam
//init the motionManager
- (void)initializeMotionManager{
motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = .1;
motionManager.gyroUpdateInterval = .1;
[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
if (!error) {
[self outputAccelertionData:accelerometerData.acceleration];
}
else{
NSLog_DEBUG(@"%@", error);
}
}];
}
//detect the device orientation
- (void)outputAccelertionData:(CMAcceleration)acceleration{
if (acceleration.x >= 0.75) {
_orientationNew = UIInterfaceOrientationLandscapeLeft;
}
else if (acceleration.x <= -0.75) {
_orientationNew = UIInterfaceOrientationLandscapeRight;
}
else if (acceleration.y <= -0.75) {
_orientationNew = UIInterfaceOrientationPortrait;
}
else if (acceleration.y >= 0.75) {
_orientationNew = UIInterfaceOrientationPortraitUpsideDown;
}
else {
// Consider same as last time
return;
}
if (_orientationNew == _orientationLast)
return;
_orientationLast = _orientationNew;
}
UIImagePickerController how to do animated switch from rear to front camera?
I was trying to do this today, and I was able to get it working with the following code:
[UIView transitionWithView:imagePickerController.view duration:1.0 options:UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionTransitionFlipFromLeft animations:^{
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
} completion:NULL];
I hope this helps anyone who comes across this question.
Weird issue with Front facing camera pictures
It turns out that I can get the result I want with smaller numbers. The front camera must have a different number of pixels than the back camera. Anyhow, if anyone is trying to do this, try smaller numbers rather than larger ones.
Related Topics
How to Draw a Circle Path with Color Gradient Stroke
Download and Cache Images in Uitableviewcell
Button Action in Mkannotation View Not Working
Sending a Private Message to Your Friends via Facebook iOS Sdk
What Is MACh-O Type Should I Use It in My iOS Objective-C Project
Is It Okay to Leave Out Unnecessary Launch Images
How to Remove Border of the Navigationbar in Swift
iOS 11 Safe Area Layout Guide Backwards Compatibility
Coremotion Updates in Background State
What Advantage(S) Does Dispatch_Sync Have Over @Synchronized
Canopenurl - This App Is Not Allowed to Query for Scheme Instragram
Ios: Capture Image from Front Facing Camera
App Store Connect Message: Your Account Will Soon Need to Be Migrated to Federated Auth
Radial Gradient Background in Swift
How to Properly Order Data from Firebase Chronologically
Create PDF with Multiple Pages
Singleton in iOS Objective C Doesn't Prevent More Than One Instance
Delivery Report of Sending Remote Push Notifications Using Apns - iOS