ioscamerauiimageuisplitview

Custom Camera view with Split View


I created many layouts with single frame to multiple frames .We should select any of the layouts after selection camera should be appeared to take pics the frames will be in split view.If we select a layout with 3 frames and we are taking pick for 2nd frame ,for first and third camera should not be applied.I also seen AVCam example code but not getting the correct one.how to use split images for custom camera.Hope someone helps.


Solution

  • Hi I got my answer by AVFoundation framework and I searched many sites and also AVCam apple example.By taking different views and imageViews,I understood where to use camera preview

     dispatch_queue_t sessionQueue = dispatch_queue_create("session queue",  DISPATCH_QUEUE_SERIAL);
     [self setSessionQueue:sessionQueue];
    
      dispatch_async(sessionQueue, ^{
      [self setBackgroundRecordingID:UIBackgroundTaskInvalid];
      NSError *error = nil;
      AVCaptureDevice *videoDevice = [SecondViewController deviceWithMediaType:AVMediaTypeVideo preferringPosition:AVCaptureDevicePositionBack];
      AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
      if (error)
        {
            NSLog(@"%@", error);
        }
    
        if ([session canAddInput:videoDeviceInput])
        {
            [session addInput:videoDeviceInput];
            [self setVideoDeviceInput:videoDeviceInput];
    
            dispatch_async(dispatch_get_main_queue(), ^{
           [[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] setVideoOrientation:(AVCaptureVideoOrientation)[self interfaceOrientation]];
            });
        }
    
        AVCaptureDevice *audioDevice = [[AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio] firstObject];
        AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error];
    
        if (error)
        {
            NSLog(@"%@", error);
        }
    
        if ([session canAddInput:audioDeviceInput])
        {
            [session addInput:audioDeviceInput];
        }
    
        AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
        if ([session canAddOutput:movieFileOutput])
        {
            [session addOutput:movieFileOutput];
            AVCaptureConnection *connection = [movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
            if ([connection isVideoStabilizationSupported])
                [connection setEnablesVideoStabilizationWhenAvailable:YES];
            [self setMovieFileOutput:movieFileOutput];
        }
    
        AVCaptureStillImageOutput *stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
        if ([session canAddOutput:stillImageOutput])
        {
            [stillImageOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}];
            [session addOutput:stillImageOutput];
            [self setStillImageOutput:stillImageOutput];
        }
    });
    

    [[self session] startRunning];

    by using this code and some important methods like deviceWithMediaType,setFlashMode I got my solution