I'm developing an iOS app with latest SDK.
I'm developing an camera app which only supports LandscapeRight orientation.
On Main ViewController
I have added a UIView
for AVCaptureVideoPreviewLayer
. In other words, main ViewController
I have main view, and another view, called videoPreviewView
, for AVCaptureVideoPreviewLayer
.
I set up AVCaptureVideoPreviewLayer
on viewWillAppear:
method:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setUpVideo];
}
- (void)setUpVideo
{
NSLog(@"Set up video");
if (DataExchanger.cameraManager != nil)
{
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:DataExchanger.cameraManager.captureSession];
CGRect bounds = [view bounds];
NSLog(@"BOUNDS: %@", NSStringFromCGRect(bounds));
[newCaptureVideoPreviewLayer setFrame:bounds];
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
}
}
I get this log:
BOUNDS: {{0, 0}, {320, 480}}
But UIInterfaceOrientation
is UIInterfaceOrientationLandscapeRight
and with that orientation I would get these values:
BOUNDS: {{0, 0}, {480, 320}}
And another problem is that I see video rotated -90 degrees.
I have found this stackoverflow question, but - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
method is never triggered.
What's happening? How can I solved this problem?