When the app launches I just want to make it display a camera view in full screen, without any on screen buttons, just the actual part which the camera is seeing.
Asked
Active
Viewed 483 times
1 Answers
1
You wont want to use the camera then. There are multiple ways to do this, the quickest is through a AVCaptureVideoPreviewLayer
Check out this answer: Get Camera Preview to AVCaptureVideoPreviewLayer
- (void)initCapture
{
AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil];
if (!captureInput) {
return;
}
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
/* captureOutput:didOutputSampleBuffer:fromConnection delegate method !*/
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[captureOutput setVideoSettings:videoSettings];
self.captureSession = [[AVCaptureSession alloc] init];
NSString* preset = 0;
if (!preset) {
preset = AVCaptureSessionPresetMedium;
}
self.captureSession.sessionPreset = preset;
if ([self.captureSession canAddInput:captureInput]) {
[self.captureSession addInput:captureInput];
}
if ([self.captureSession canAddOutput:captureOutput]) {
[self.captureSession addOutput:captureOutput];
}
//handle prevLayer
if (!self.captureVideoPreviewLayer) {
self.captureVideoPreviewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
}
//if you want to adjust the previewlayer frame, here!
self.captureVideoPreviewLayer.frame = self.view.bounds;
self.captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer addSublayer: self.captureVideoPreviewLayer];
[self.captureSession startRunning];
}
Also see:

Community
- 1
- 1

John Riselvato
- 12,854
- 5
- 62
- 89
-
Added that into viewcontroller.m. Comes up with error for - (void)initCapture use of undeclared identifier 'initCapture' then warning for @implementation ViewController. How do i fix this and also connect this code to the storyboard with what item to make the thing work – Harvey May 24 '14 at 12:14
-
the error for @implementation ViewController is Method definition for 'initCapture' not found – Harvey May 24 '14 at 12:50