2010-08-12 104 views
1

我目前正在開發一款應用程序,它使用UIImagePickerController來使用相機內置照片拍攝照片。相機問題

我不想做的是爲用戶提供UIImagePickerController的底部開關,以便能夠在前部和後部攝像頭之間切換(當然如果有的話)。我知道如何確定是否有前置攝像頭,但我怎樣才能在底部欄上顯示這樣的開關?

謝謝你的幫助!

回答

0

請將您的UIImagePickerControllershowsCameraControls設置爲YES,或者提供您自己的控件cameraOverlayView

對於前後攝像頭之間的切換,請使用UIImagePickerControllercameraDevice屬性。

+0

他的意思是他怎麼能打** **顯示的前置攝像頭。 – elslooo 2010-08-12 09:35:24

+0

引用問題:「......但我怎麼能顯示這樣一個開關......」 – tobiasbayer 2010-08-12 09:49:26

+0

引用了這個問題:「...能夠在前後攝像頭之間切換」,所以他意味着他如何能夠顯示一個開關**,顯示前置攝像頭開啓時的狀態**。 – elslooo 2010-08-12 10:00:21

1

.h文件 @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; 


}