title: AVCaptureSession startRunning makes AVCaptureVideoPreviewLayer black first
body: <p>Recently, I am developing QR Code Recognition on iPhone. I use AVFoundation framework. I use <strong>AVCaptureSession</strong> to connect with AVCaptureDeviceInput and AVCaptureMetadataOutput and use <strong>AVCaptureVideoPreviewLayer</strong> to display.
  The issue is that When AVCaptureSession startRunning, <strong>AVCaptureVideoPreviewLayer first becomes black and gradually return to normal.</strong> The issue is a poor user experience. Now I use GCD's dispatch_after() to solve this issue temporarily. I know is there any other solutions.
  Because AVCaptureSession's startRunning method is time-consuming, I call startRunning() on the background thread. I use a loading view to make user wait for the AVCaptureSession start. I observe "AVCaptureSessionDidStartRunningNotification" notification. But when the notification posted the AVCaptureVideoPreviewLayer still black first and gradually return to normal.</p>
  
  <pre><code>dispatch_async(self.sessionQueue, ^{
              [_avSession startRunning];
              CGRect rectOfInterest = [_previewLayer metadataOutputRectOfInterestForRect:_config.rectOfInterest];
              _metadataOutput.rectOfInterest = rectOfInterest;
          }
      }
  });
  
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(avSessionDidStartRunning) name:AVCaptureSessionDidStartRunningNotification object:nil];
  </code></pre>