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

2 回答 2

5

最后我得到了答案。我为 overlayview 创建 UIView 子类并覆盖以下方法,它将忽略对 overlayView 的触摸。

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{

return NO;
}
于 2013-08-02T11:01:09.360 回答
3

尝试使用覆盖的 hitTest: withEvent: 来覆盖 UIView 子类的实例。如果您不希望它或它的任何子视图接收触摸,它会是这样的:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    return nil;
}
于 2013-08-02T09:06:34.953 回答