我希望能够通过按钮更改UIImagePickerControllerCameraDevice。我想要使用的按钮放置在运行时显示在ImagePicker顶部的叠加层中。
我有一个想法,这将要求我使用代表,但我对代表的知识非常少。有人能指出我正确的方向吗?
这是我用于我的UIImagePickerController“GetPhoto”的代码,它检查设备是否有摄像头并根据您可用的情况启动正确的摄像头,如果没有,则会给你摄像头。< / p>
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == takePictureButton) {
overlayViewController *overlay = [[overlayViewController alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceFront]) {
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
else {
picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
picker.cameraOverlayView = overlay;
}
else {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = YES;
}
}
[self presentModalViewController:picker animated:YES];
[picker release];
}
答案 0 :(得分:2)
由于您正在使用与叠加层关联的视图控制器,因此您可以在叠加层视图控制器中为图像选择器控制器定义属性,可能是assign
而不是retain
并定义操作覆盖视图控制器中的按钮,以影响该属性引用的图像选择器控制器实例。