4

I have a simple camera app, that has a AVCaptureVideoPreviewLayer inside a View.

I also have a button that triggers the AVCaptureSession to swap input between the rear and the front cameras.

I'd love to cause a flip animation when the change happens but I can't work out how to do it...

I was thinking I'd try and overlay a freezeframe of the AVCaptureVideoPreviewLayer and then transition this layer swapping back with the AVCaptureVideoPreviewLayer.

Any pointers would really be gratefully received

buildmaster
  • 308
  • 1
  • 11

1 Answers1

3

If your AVCaptureVideoPreviewLayer is inside a UIView, you should probably make a transition with this UIView.

Use one of these methods:

+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

With UIViewAnimationOptions set on UIViewAnimationOptionTransitionFlipFromLeft or UIViewAnimationOptionTransitionFlipFromRight

Giuseppe Garassino
  • 2,272
  • 1
  • 27
  • 47
  • 1
    Hey @Beppe, how would this happen if you don't have 2 views? I basically have a CameraViewController that shows a UIImagePickerController and I call setCameraDevice and pass the appropriate UIImagePickerControllerCameraDevice. – Kevin Zych Aug 23 '13 at 03:32
  • @KevinZych If you present UIImagePickerController as a modal view (and you should on iPhone and iPod touch), I think your best try is working with UIViewAnimationTransition/modalTransitionStyle. Take a look here (old but still useful) http://stackoverflow.com/q/237310/1146089 – Giuseppe Garassino Aug 23 '13 at 09:14