I have been using custom overlay for UIImagePickerController
controller, and everything is working fine. I have added button to switch between front and rear camera via -
- (IBAction)changeCamera:(id)sender {
if (self.imagePicker.cameraDevice == UIImagePickerControllerCameraDeviceRear) {
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
else {
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
}
Problem is, switch is not animated. I have been using apple camera app which is built on top of UIImagePicker, and the switch is happening animated. How do I do this?
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.
Here's the Swift code for the accepted answer in case someone needs it:
UIView.transitionWithView(imagePickerController.view!, duration: 1.0, options: [.AllowAnimatedContent, .TransitionFlipFromLeft], animations: {() -> Void in
imagePickerController.cameraDevice = .Rear
}, completion: nil)
Thanks Pablo!
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