UIImagePickerController如何从后置摄像头到前置摄像头进行动画切换?

时间:2012-10-09 08:32:34

标签: iphone camera uiimagepickercontroller uiviewanimation

我一直在为UIImagePickerController控制器使用自定义叠加层,一切正常。我已添加按钮,通过 -

在前后摄像头之间切换
 - (IBAction)changeCamera:(id)sender {
if (self.imagePicker.cameraDevice == UIImagePickerControllerCameraDeviceRear) {
    self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
else {
    self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
}

问题是,切换没有动画。我一直在使用建立在UIImagePicker之上的苹果相机应用程序,并且开关正在发生动画。我该怎么做?

2 个答案:

答案 0 :(得分:24)

我今天试图这样做,我能够使用以下代码:

[UIView transitionWithView:imagePickerController.view duration:1.0 options:UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionTransitionFlipFromLeft animations:^{
            imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
        } completion:NULL];

我希望这可以帮助任何遇到这个问题的人。

答案 1 :(得分:4)

如果有人需要,这是接受答案的Swift代码:

UIView.transitionWithView(imagePickerController.view!, duration: 1.0, options: [.AllowAnimatedContent, .TransitionFlipFromLeft], animations: {() -> Void in
            imagePickerController.cameraDevice = .Rear
            }, completion: nil)

谢谢Pablo!