gpt4 book ai didi

objective-c - 当点击覆盖中的按钮时,带有相机 OverlayView 的 UIImagePickerController 聚焦

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:58 32 4
gpt4 key购买 nike

我是 Objective C 的新手,这是我在这里发布的第一个问题,所以这可能是世界上最容易回答的问题,但我想不出这个问题。

我正在尝试创建一个使用相机的 iOS 应用程序。我使用 UIImagePickerController 类来显示相机和拍照,但我使用 cameraOverlayView 属性创建了一个自定义 UIView,其中包含一堆覆盖相机预览框架的 UIButton 实例。我正在使用 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,但底层相机 View 也会被点击并重新聚焦。因此,每次按下按钮时,我都必须在拍照前手动重新对焦相机预览。如您所见,我尝试使用 bringSubViewToFront:,但这似乎不起作用。

当我点击 cameraOverlayView 上的按钮时,如何防止相机对焦?

感谢您的帮助!

最佳答案

将此添加到您的代码中:hitTest:withEvent:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hittedView = [super hitTest:point withEvent:event];
return hittedView == self.button ? hittedView : nil;
}

我引用了这个: UserInteraction enable for subview only .我已经测试了代码。并且有效!

关于objective-c - 当点击覆盖中的按钮时,带有相机 OverlayView 的 UIImagePickerController 聚焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13375568/

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