• The problem

    The leader arranges the task, writes a photo function, the interface takes a photo with the system a little discrepancy

    After the photo is taken, the bottom shows the photo taken. There is a cap on the photo taken.

    Click the photo taken, you can preview, zoom in and out of view

  • Train of thought

    The system must not take photos, can only be customized, did not mention whether to take photos to prohibit the demand of sound [non-candid, serious people]

    In principle can be simple is not complex, brick AVCAPTUREPHOTOOUTPUT

  • Smooth your

    First, you need a temporary layer for the current scene, not mentioned here. Refer to the previous post.

    Next, define session + photoOutput

    Third, define the photo event

    Finally, the agent gets the photo

  • serving

    • Session defines the input Settings

      self.session = [[AVCaptureSession alloc] init];
      self.session.sessionPreset = AVCaptureSessionPresetPhoto;
      AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
      self.dInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
      if ([self.session canAddInput:self.dInput]) {
          [self.session addInput:self.dInput];
      }
    • Camera Scene Layer

      self.preView = [[AVPreView alloc] init];
      self.preView.backgroundColor = [UIColor colorWithHexs:0x3f3f3f];
      self.preView.session = self.session;
      [self.preView setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
      [self.view addSubview:self.preView];
      [self.preView mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.equalTo(self.view);
          make.top.equalTo(self.topView.mas_bottom);
          make.bottom.equalTo(self.collect.mas_top);
          make.right.equalTo(rightView.mas_left);
      }];
    • Set the photoOutput

      self.photoOutput = [[AVCapturePhotoOutput alloc] init];
      if ([self.session canAddOutput:self.photoOutput]) {
          [self.session addOutput:self.photoOutput];
      }
      [self.photoOutput.connections.lastObject setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
    • session start

      [self.session startRunning];
    • Photo click

      AVCapturePhotoSettings *set = [AVCapturePhotoSettings photoSettings];
      [self.photoOutput capturePhotoWithSettings:set delegate:self];
    • AVCapturePhotoCaptureDelegate

      #pragma mark - AVCapturePhotoCaptureDelegate -(void)captureOutput:(AVCapturePhotoOutput *)output DidFinishProcessingPhoto photo: (AVCapturePhoto *) error: (NSError *) error API_AVAILABLE (ios (11.0)) {if (! NsData *data = [Photo FileDatarePresentation]; UIImage *image = [UIImage imageWithData:data]; // image}}
  • Game Over.

    See me Tomorrow, haha