21

我一直在为UIImagePickerController控制器使用自定义叠加层,一切正常。我添加了按钮以通过 - 在前后摄像头之间切换 -

 - (IBAction)changeCamera:(id)sender {
if (self.imagePicker.cameraDevice == UIImagePickerControllerCameraDeviceRear) {
    self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
else {
    self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
}

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

4

2 回答 2

25

我今天尝试这样做,并且能够使用以下代码使其工作:

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

我希望这对遇到这个问题的人有所帮助。

于 2013-03-12T04:57:57.490 回答
7

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

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

谢谢巴勃罗!

于 2016-08-08T07:26:56.590 回答