iPhone应用程序 - 在横向模式下显示AVFoundation视频

问题描述:

我正在使用来自Apple的AVCam示例应用程序。iPhone应用程序 - 在横向模式下显示AVFoundation视频

本示例使用AVFoundation为了在视图上显示视频。

我想从AVCam做一个风景应用程序没有运气。

当屏幕方向改变时,视频显示在视图上旋转。有没有办法处理这个问题?

当您创建预览层:

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); 
} 

为我工作。

+1

注意:由于方向属性已弃用,因此您需要[在连接上设置videoOrientation属性](http://stackoverflow.com/a/22187500/35690)。 – Senseful 2014-03-05 02:53:23

您是否使用预览图层的方向和重力设置?

previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session]; 
previewLayer.frame = CGRectMake(0, 0, 480, 300); 
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight; 
previewLayer.automaticallyAdjustsMirroring = YES; 

申报

- (BOOL)shouldAutorotate; 

在.H。

然后做:

在您的m

这将迫使它不能转动

- (BOOL)shouldAutorotate { 
    return NO; 
}