2011-06-08 121 views

回答

10

当您创建预览层:

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

0

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

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

申报

- (BOOL)shouldAutorotate; 

在.H。

然后做:

在您的m

这将迫使它不能转动

- (BOOL)shouldAutorotate { 
    return NO; 
} 

相关问题