我是 Objective C 的新手,这是我在这里发布的第一个问题,所以这可能是世界上最容易回答的问题,但我无法弄清楚这个问题。
我正在尝试创建一个使用相机的 iOS 应用程序。我正在使用 UIImagePickerController 类来显示相机并拍照,但我创建了一个自定义 UIView,其中包含一堆 UIButton 实例,这些实例覆盖相机预览帧,使用 cameraOverlayView 属性。我正在使用 a 方法通过以下代码将相机放在屏幕上:
- (BOOL) startCameraControllerFromViewController: (UIImagePickerController*) imagePickerController
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) imagePickerControllerDelegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (imagePickerController == nil)
|| (imagePickerControllerDelegate == nil))
return NO;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
imagePickerController.allowsEditing = NO;
imagePickerController.showsCameraControls = NO;
imagePickerController.wantsFullScreenLayout = YES;
imagePickerController.delegate = imagePickerControllerDelegate;
self.cameraOverlayViewController = [[CameraOverlayViewController alloc] initWithImagePickerControllerDelegate:imagePickerController nibName:@"CameraOverlayView" bundle:nil];
self.cameraOverlayViewController.view.frame = CGRectMake(0, 0, imagePickerController.view.frame.size.width, imagePickerController.view.frame.size.height);
imagePickerController.cameraOverlayView = self.cameraOverlayViewController.view;
[self presentViewController:imagePickerController animated:self.showCameraAnimation completion:^(void) {
[self.view bringSubviewToFront:self.cameraOverlayViewController.view];
}];
return YES;
}
当我按下位于相机预览窗口顶部的按钮时,相应的 IBAction 会被触发,但底层的相机视图也会被点击并重新聚焦。因此,每次按下按钮时,我都必须手动重新对焦相机预览,然后才能拍照。如您所见,我尝试使用bringSubViewToFront:,但这似乎不起作用。
当我点击 cameraOverlayView 上的按钮时,如何防止相机对焦?
谢谢你的帮助!