2013-08-02 21 views
8

我想補充的覆蓋查看和移動&規模功能,拍攝的圖像,但我不能這樣做,因爲覆蓋鑑於這種不工作。移動和縮放時OverlayView的設置相機

這裏是我的代碼:

-(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)]; 
[email protected]"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; 
[email protected]"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]; 
} 

回答

3

嘗試使覆蓋與重載則hitTest一個UIView子類的實例:withEvent :.如果你不希望它或任何其子視圖接收觸摸,這將是這樣的:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 
    return nil; 
} 
+0

是johnyu,我試過了,但仍然沒有工作 –

+0

沒有這overlayView一切工作正常?另外,你是否嘗試過在所有疊加子視圖上設置userInteractionEnabled = NO? – johnyu

+0

是沒有這種覆蓋一切正常fine.And我嘗試了所有子視圖的userInteractionEnabled = NO; –

5

最後我得到的答案。 我爲overlayview創建UIView子類並重寫下面的方法,它會忽略overlayView的觸摸。

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

return NO; 
}