2
這是我如何在我的iPad3設立在風景模式下,相機預覽相機預覽不會填充屏幕
- (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];
}
在故事板,我設置視圖來填充整個屏幕,但它看起來像這樣:
此外,圖像也旋轉90º度。我怎樣才能改變這個,所以我可以讓相機預覽填滿整個屏幕?
謝謝。
這indeeds工作。 HOwever我結束了使用captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft; 謝謝! – MobileCushion
請注意,AVCaptureVideoPreviewLayer.orientation被標記爲已棄用 – CSmith