My application is composed of a toolbar and an AVCaptureVideoPreviewLayer in a background UIView. I\'d like to see that toolbar rotate regarding the device orientation, so in my
This post pointed in the right direction. To get an AVCaptureVideoPreviewLayer
to not rotate with the device I wrapped it in a UIView
and animated that view in the opposite direction:
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
float rotation;
if (toInterfaceOrientation==UIInterfaceOrientationPortrait) {
rotation = 0;
} else
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
rotation = M_PI/2;
} else
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) {
rotation = -M_PI/2;
}
[UIView animateWithDuration:duration animations:^{
cameraPreview.transform = CGAffineTransformMakeRotation(rotation);
cameraPreview.frame = self.view.frame;
}];
}
It seems a little roundabout but it animates smoothly. Other views on top of the preview layer automatically rotate as they should.