开发者

Problem with the camera

开发者 https://www.devze.com 2023-01-11 01:02 出处:网络
I am currently developing an app which is using the UIImagePickerControll开发者_开发知识库er for taking pictures with the build in camera.

I am currently developing an app which is using the UIImagePickerControll开发者_开发知识库er for taking pictures with the build in camera.

What I no want to do, is to provide the user a switch on bottom bar of the UIImagePickerController to be able to switch between the front and the rear camera (if available of course). I know how it's possible to determine if there's a front camera, but how can I show such a switch on the bottom bar?

Thanx for all your help!


.h file @property(nonatomic) UIImagePickerControllerCameraDevice cameraDevice;

cameraButtonPressed method opens the rear camera. changeCam method toggles between rear and front camera.

.m file


-(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;


}


Either set showsCameraControlsof your UIImagePickerController to YES or provide your own controls with cameraOverlayView.

For switching between front and rear camera use the cameraDevice property of UIImagePickerController.

0

精彩评论

暂无评论...
验证码 换一张
取 消