I want to capture an image with the camera using AVCaptureSession.
It works ok, I start the camera and I can get the output. However, I have some problems with video orientation when I rotate the device.
First, I want to support landscape left and right orientations and may be portrait modes too later.
I implement:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation{
return UIInterfaceOrientationIsLandscapse(interfaceOrientation);
}
When I rotate the device, it rotates the app from landscape left to landscape right or vice versa, but I only see the camera correctly when I'm on landscape left. When the app is on landscape right, the video is rotated by 180 degrees.
Thank you very much.
Update:
I've tried Spectravideo328 answer but I have an error when I try to rotate the device and the app crash. This is the error:
[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210'
The error occurs in this line:
AVCaptureConnection *previewLayerConnection=self.previewLayer.connection;
I put it inside shouldAutorotateToInterfaceOrientation method.
Do you know what could be the reason of this error?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…