2012-10-03 4 views
2

Voilà comment je suis en train de l'aperçu de la caméra en mode paysage dans mon iPad3Aperçu L'appareil photo ne remplit pas l'écran

- (void)viewDidAppear:(BOOL)animated 

{

AVCaptureSession *session = [[AVCaptureSession alloc] init]; 
session.sessionPreset = AVCaptureSessionPreset640x480; 

CALayer *viewLayer = self.vImagePreview.layer; 

NSLog(@"viewLayer = %@", viewLayer); 

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; 

captureVideoPreviewLayer.frame = self.vImagePreview.bounds; 
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer]; 

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 

NSError *error = nil; 
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; 
if (!input) { 
    // Handle the error appropriately. 
    NSLog(@"ERROR: trying to open camera: %@", error); 
} 
[session addInput:input]; 

stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; 
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; 
[stillImageOutput setOutputSettings:outputSettings]; 

[session addOutput:stillImageOutput]; 

[session startRunning]; 

}

Dans le story-board, je définir la vue pour remplir l'écran entier, mais il finit par ressembler à ceci:

enter image description here

Et en outre, l'image est également pivotée de 90 degrés. Comment puis-je changer cela, pour que l'aperçu de la caméra remplisse tout l'écran?

Merci.

Répondre

3

Faites pivoter votre couche:

switch (self.interfaceOrientation) 
    { 
    case UIInterfaceOrientationLandscapeRight: 
     [captureVideoPreviewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI/2)]; 
     break; 
    case UIInterfaceOrientationLandscapeLeft: 
     [captureVideoPreviewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI/2)]; 
     break; 
    } 

[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer]; 
+0

Ce indeeds travail. Cependant, j'ai fini par utiliser captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft; Merci beaucoup! – MobileCushion

+0

s'il vous plaît noter que AVCaptureVideoPreviewLayer.orientation est marqué déprécié – CSmith