问题描述
在我的应用程序中,我向摄像师添加了 cameraOverlayView
。它包含三个子视图,两个 UIButtons
和一个 UIImageView
。图像是可拖动的。
In my application, I added a cameraOverlayView
to the camerapicker. It contains three subviews, two UIButtons
and one UIImageView
. The image is draggable. The buttons are used to change the image to another one.
当我触摸按钮或图像时,相机的拍摄对焦矩形将始终为显示在下面(并且实际焦点将改变)。在所有三个子视图中设置 exclusiveTouch
到到
不会改变行为。
When I touch a button, or the image, the tap-to-focus rect of the camera will always be displayed beneath (and the actual focus will change). Setting exclusiveTouch
to YES
on all three subviews doesn't change the behaviour.
任何想法,我怎么可以阻止摄影师获得我的重叠视图的按钮/子视图的触摸(但仍然得到触摸对焦,切换摄像头等)?
Any idea, how i can stop the camerapicker from getting the touches of my buttons / subviews of my overlayview (but still getting the touches for touch-to-focus, switching cameras etc.)?
提供更多信息。我使用下面的代码,允许相机交互时有一个overlayview,这些子视图仍然得到触摸。
To give some more information. I'm using the following code, to allow camera interaction while having an overlayview, which subviews still get the touches.
// 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;
}
推荐答案
停止这一点,我发现。没有办法做我真正想要做的。但是调整它会给你一些可用的东西。
There are a couple of ways to stop this that I found. None of the ways do exactly what I would like it to do. But tweaking it around should give you something usable.
1)禁用相机控制。 cameraPickerController.showsCameraControls = NO;
这将最终取消触摸从屏幕的焦点,但它也会删除其他控件。
1.) Disable camera control. cameraPickerController.showsCameraControls = NO;
This will ultimately take down the touch to focus from the screen but it would take down other controls too.
2。)控制overlayView中的hitTest并将这些区域设置为nil。这个解决方案是非常尴尬,但它适用于我。
2.) Control the hitTest in your overlayView and set those area to nil. This solution is very awkward but it works for me.
这是我管理面罩的overlayView
This is my overlayView that manages a face mask
- (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;
}
所以如果你调整,这将适合你。我仍然在寻找魔术棒,使这项工作没有所有的黑客。没有符号:(
So if you get tweaking, this will work for you. I am still looking for the magic wand that make this work without all the hacks. No sign of it still :(
这篇关于在iOS中的相机覆盖视图中的暴光触摸(camerapicker)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!