当覆盖视图设置为相机时,移动和缩放无法正常工作

8

我正在尝试为捕获的图像添加覆盖视图和移动/缩放功能,但由于覆盖视图的存在,我无法实现这一点。

以下是我的代码:

-(void)showOverlayCamera
{

UIImagePickerController *pickerObj = [[UIImagePickerController alloc] init];
pickerObj.delegate = self;
pickerObj.allowsEditing = YES;
pickerObj.sourceType = UIImagePickerControllerSourceTypeCamera;

// creating overlayView
UIView* overlayView = [[UIView alloc] initWithFrame:self.view.bounds];
UIImageView *logoImgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"logo.png"]];
logoImgView.frame=CGRectMake(10, 10, 100, 20);
[overlayView addSubview:logoImgView];

//add lable in overlay view
UILabel *headerLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, logoImgView.frame.origin.y+logoImgView.frame.size.height+10, 250, 40)];
headerLabel.text=@"New Scan";
headerLabel.textColor=[UIColor whiteColor];
headerLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:40];
headerLabel.backgroundColor=[UIColor clearColor];
[overlayView addSubview:headerLabel];

//add square image in overlay view
squareImgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cameraBorder.png"]];
squareImgView.frame=CGRectMake(60, headerLabel.frame.origin.y+headerLabel.frame.size.height+20, 200, 200);
[overlayView addSubview:squareImgView];

//adding lable in overlay view
UILabel *instructionLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, squareImgView.frame.origin.y+squareImgView.frame.size.height+5, 250, 60)];
instructionLabel.numberOfLines=2;
instructionLabel.text=@"Focus your mole in the center of square";
instructionLabel.textColor=[UIColor whiteColor];
instructionLabel.font=[UIFont fontWithName:@"Helvetica" size:20];
instructionLabel.backgroundColor=[UIColor clearColor];
[overlayView addSubview:instructionLabel];

[overlayView.layer setOpaque:NO];
overlayView.opaque = NO;
//adding overlay view on camera
[pickerObj setCameraOverlayView:overlayView];
[self presentViewController:pickerObj animated:YES completion:nil];
}
2个回答

5
最后我得到了答案。 我创建了一个UIView子类用于遮罩视图,并覆盖了以下方法,它将忽略对遮罩视图的触摸。
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{

return NO;
}

3
试着让覆盖层成为UIView子类的实例,并重写hitTest:withEvent:方法。如果您不希望它或其任何子视图接收触摸事件,则应该像这样操作:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    return nil;
}

没有那个overlayView,一切都正常工作吗?另外,您是否尝试将userInteractionEnabled = NO设置为所有覆盖层的子视图? - johnyu
是的,没有那个覆盖层一切都正常。我尝试了所有子视图的userInteractionEnabled = NO; - Prashant Chaudhari
修改了答案,这应该会有所帮助。 :) - johnyu
谢谢johnyu,我找到了解决方案,也使用了你的方法。两种方式都很好用。 - Prashant Chaudhari

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接