问题
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?
回答1:
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.
回答2:
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!
来源:https://stackoverflow.com/questions/12795926/uiimagepickercontroller-how-to-do-animated-switch-from-rear-to-front-camera