在我的应用程序中,我向摄像机添加了cameraOverlayView
。它包含三个子视图,两个UIButtons
和一个UIImageView
。图像是可拖动的。这些按钮用于将图像更改为另一个图像。
当我触摸按钮或图像时,相机的点击对焦矩形将始终显示在下方(实际焦点将会改变)。在所有三个子视图中将exclusiveTouch
设置为YES
不会改变行为。
任何想法,我怎么能阻止摄像机拍摄我的叠加视图的按钮/子视图的触摸(但仍然可以触摸到对焦,切换相机等等)?
提供更多信息。我正在使用以下代码,以便在拥有覆盖视图时允许相机交互,哪些子视图仍然可以触及。
// CameraOverlayView.m
[...]
// ignore touches on this view, but not on the subviews
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
id hitView = [super hitTest:point withEvent:event];
if (hitView == self) return nil;
else return hitView;
}
答案 0 :(得分:0)
我发现有几种方法可以阻止这种情况。没有一种方法可以完全按照我的意愿去做。但是调整它应该会给你一些可用的东西。
1。)禁用相机控制。 cameraPickerController.showsCameraControls = NO;
这最终将触及屏幕上的焦点,但它也会取消其他控件。
2.。)在overlayView中控制hitTest并将这些区域设置为nil。这个解决方案很尴尬,但它对我有用。
这是我管理面具的overlayView
- (id)initWithFrame:(CGRect)frame imagePicker: (UIImagePickerController *) imagepicker{
self = [super initWithFrame:frame];
if (self) {
faceMaskButton = [UIButton buttonWithType:UIButtonTypeCustom];
faceMaskButton.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:.2];
faceMaskButton.frame = CGRectMake(10, 10, 70, 35);
faceMaskButton.layer.borderColor = [[UIColor colorWithRed:0 green:0 blue:0 alpha:.6] CGColor];
faceMaskButton.layer.borderWidth = 1;
faceMaskButton.layer.cornerRadius = 17;
[faceMaskButton setImage:[UIImage imageNamed:@"Facemask button"] forState:UIControlStateNormal];
[faceMaskButton addTarget:self action:@selector(facemask) forControlEvents:UIControlEventTouchDown];
faceMaskButton.exclusiveTouch = YES;
faceMaskButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[self addSubview:faceMaskButton];
loadingFacemask = NO;
overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Camera Face Overlay"]];
overlayImage.frame = CGRectMake((self.bounds.size.width - 400)/2, (self.bounds.size.height - 400)/3, 400, 400);
overlayImage.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
overlayImage.alpha = 0.9f;
[self addSubview:overlayImage];
imagePickerController = imagepicker;
}
return self;
}
- (void) facemask{
if (!loadingFacemask) {
loadingFacemask = YES;
[UIView animateWithDuration:.3 animations:^{
overlayImage.alpha = overlayImage.alpha? 0:1;
faceMaskButton.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
} completion:^(BOOL finished) {
faceMaskButton.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:.2];
loadingFacemask = NO;
}];
}
}
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
if ((self.bounds.size.height - 44)<point.y){
return imagePickerController.view;
}
if (point.x < faceMaskButton.bounds.origin.x + faceMaskButton.bounds.size.width +10 && point.y < faceMaskButton.bounds.origin.y + faceMaskButton.bounds.size.height + 10) {
[self facemask];
return nil;
}
return self;
}
因此,如果你进行调整,这对你有用。我仍然在寻找能够在没有任何黑客攻击的情况下完成这项工作的魔杖。没有任何迹象:(