iOS taking photo programmatically

前端 未结 5 2037
执笔经年
执笔经年 2020-11-28 07:44

I know this is possible, saw this in some apps (iGotYa is I believe the most famous). I know how to set up everything for taking photos, saving it and everything. But how ca

5条回答
  •  半阙折子戏
    2020-11-28 08:08

    You can also do it without AVFoundation and it is in my opinion an easier way to implement it using only the UIImagePickerController. There are 3 conditions:

    1. Obviously the device needs to have a camera
    2. You must hide the camera controls
    3. Then simply use the takePicture method from UIImagePickerController

    Below is a simple example that you woul typically trigger after a button push

    - (IBAction)takePhoto:(id)sender 
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        picker.showsCameraControls = NO;
        [self presentViewController:picker animated:YES
                         completion:^ {
                             [picker takePicture];
                         }];
    }
    

提交回复
热议问题