gpt4 book ai didi

iphone - UIImagePickerController 通过委托(delegate)更改相机源?

转载 作者:行者123 更新时间:2023-11-29 11:22:33 25 4
gpt4 key购买 nike

我希望能够通过按钮更改 UIImagePickerControllerCameraDevice。我想使用的 Button 放置在一个叠加层中,该叠加层在运行时显示在 ImagePicker 的顶部。

我有一种暗示,这将需要我使用委托(delegate),但我对委托(delegate)的了解非常少。有人能指出我正确的方向吗?

这是我用于我的 UIImagePickerController“GetPhoto”的代码,它检查设备是否有摄像头,并在启动时根据可用的摄像头启用正确的摄像头,如果没有,它会为您提供相机胶卷。

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

最佳答案

由于您使用的是与叠加层相关联的 View Controller ,因此您可以在叠加层 View Controller 中为图像选择器 Controller 定义一个属性,可能是assign而不是retain编辑并定义覆盖 View Controller 中按钮的操作,以影响该属性引用的图像选择器 Controller 实例。

关于iphone - UIImagePickerController 通过委托(delegate)更改相机源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6188332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com