.h file @property (nonatomic) UIImagePickerControllerCameraDevice cameraDevice;
Метод cameraButtonPressed открывает заднюю камеру.Метод changeCam переключает между задней и передней камерой.
.m файл
-(void) cameraButtonPressed
{
overLay=[[UIView alloc]initWithFrame:CGRectMake(0,0, 320, 480)];
UIImage *CameraClickImg=[UIImage imageNamed:@"capture.png"];
UIButton *captureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[captureBtn setFrame:CGRectMake(35,440, 240,40)];
[captureBtn addTarget:self action:@selector(captureImage) forControlEvents:UIControlEventTouchUpInside];
[captureBtn setImage:CameraClickImg forState:UIControlStateNormal];
UIButton *changeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[changeBtn setFrame:CGRectMake(250,30, 40,40)];
[changeBtn addTarget:self action:@selector(changeCam) forControlEvents:UIControlEventTouchUpInside];
[changeBtn setImage:CameraClickImg forState:UIControlStateNormal];
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
picker.cameraOverlayView=overLay;
[self presentModalViewController: picker animated:YES];
[overLay addSubview:captureBtn];
[overLay addSubview:changeBtn];
[picker release];
[self.view addSubview:activityIndicator];
}
-(void)captureImage
{
[picker takePicture];
}
-(void)changeCam
{
if (picker.cameraDevice==UIImagePickerControllerCameraDeviceRear)
picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;
else
picker.cameraDevice=UIImagePickerControllerCameraDeviceRear;
}