AVCaptureVideoPreviewLayer方向错误

时间:2014-09-12 05:32:38

标签: objective-c xcode cocoa

我有奇怪的问题。我正在我的应用中录制视频。一切正常,直到我将设备旋转180度。在我开始游戏的横向模式中,视频正确启动并不重要,但是一旦我从横向左转到右视图,视频就会开始垂直记录。我抽签示意: enter image description here

我正在设置像这样的视频方向: - (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; 仍然无法运作

1 个答案:

答案 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;
   }
}