我正在设置像这样的视频方向: - (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"Left");
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
return YES;
}
else if(orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Right");
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
return YES;
}
return NO;
} 但这似乎根本不起作用。我设置了captureVideoPreviewLayer.frame = self.view.bounds; 仍然无法运作
答案 0 :(得分:1)
你所做的是正确的,除了我不确定你所采取的方向。我认为应该是
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
以下是您可以尝试从shouldAutorotate
方法调用它的完整方法:
- (void)autoRotateVideoOrientation {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
switch (orientation) {
case UIInterfaceOrientationPortrait:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIInterfaceOrientationPortraitUpsideDown:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
case UIInterfaceOrientationLandscapeLeft:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIInterfaceOrientationLandscapeRight:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
default:
break;
}
}