Приложение для iPhone - Показать видео AVFoundation в ландшафтном режиме
Я использую пример приложения AVCam от Apple.
Этот пример использует AVFoundation для показа видео на представлении.
Я пытаюсь сделать из AVCam ландшафтное приложение без удачи.
При изменении ориентации экрана видео отображается повернутым на виде. Есть ли способ решения этой проблемы?
3 ответа
Решение
Когда вы создаете слой предварительного просмотра:
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
И методы управления вращениями:
-(void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[CATransaction begin];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
} else {
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
}
[CATransaction commit];
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Это сработало для меня.
Используете ли вы настройки ориентации и гравитации для слоя предварительного просмотра?
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = CGRectMake(0, 0, 480, 300);
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
previewLayer.automaticallyAdjustsMirroring = YES;
Декларировать
- (BOOL)shouldAutorotate;
в вашем.ч.
Затем сделайте:
- (BOOL)shouldAutorotate {
return NO;
}
в твоем.m
Это заставит его не вращаться.