我一直在为UIImagePickerController
控制器使用自定义叠加层,一切正常。我已添加按钮,通过 -
- (IBAction)changeCamera:(id)sender {
if (self.imagePicker.cameraDevice == UIImagePickerControllerCameraDeviceRear) {
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
else {
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
}
问题是,切换没有动画。我一直在使用建立在UIImagePicker之上的苹果相机应用程序,并且开关正在发生动画。我该怎么做?
答案 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!