title: creating custom camera with square view on iOS
body: <p>I am trying to create a custom camera experience on iOS and the following code snippet is as far as I got. Basically I want the usual camera view (i.e. with the following buttons: capture, flash, grid, front/back, cancel). But the only difference between the normal camera and mine is that I want <strong>a square for the preview surface</strong>; not a rectangle. And then, what you see is what you get (WYSIWYG) such that there is no cropping necessary; as the user would have taken a square picture in the first place.</p>
  
  <p>I have also been looking at the library <a href="https://github.com/danielebogo/DBCamera">https://github.com/danielebogo/DBCamera</a> but I am not seeing how to customize it to my end. Any help? Thanks.</p>
  
  <p>MY CODE SO FAR:</p>
  
  <pre><code>- (void)viewDidLoad {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
  
      //Capture Session
      AVCaptureSession *session = [[AVCaptureSession alloc]init];
      session.sessionPreset = AVCaptureSessionPresetPhoto;
  
      //Add device
      AVCaptureDevice *device =
      [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  
      //Input
      AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
  
      if (!input)
      {
          NSLog(@"No Input");
      }
  
      [session addInput:input];
  
      //Output
      AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
      [session addOutput:output];
      output.videoSettings =
      @{ (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA) };
  
      //Preview Layer
      AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
      UIView *myView = self.view;
      previewLayer.frame = myView.bounds;
      previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
      [self.view.layer addSublayer:previewLayer];
  
      //Start capture session
      [session startRunning];
  }
  </code></pre>
  
  <p>This is the only custom code in a single view project on Xcode</p>