2

私のアプリケーションではcameraOverlayView、カメラピッカーに を追加しました。これには、 twoUIButtonsと oneの 3 つのサブビューが含まれていますUIImageView。画像はドラッグ可能です。ボタンは、画像を別の画像に変更するために使用されます。

ボタンまたは画像に触れると、カメラのタップしてフォーカスする四角形が常に下に表示されます (実際のフォーカスが変わります)。exclusiveTouch3 つのサブビューすべてをon に設定し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;
}
4

1 に答える 1

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

したがって、微調整を行うと、これが機能します。私はまだ、すべてのハックなしでこれを機能させる魔法の杖を探しています. まだその兆候はありません:(

于 2012-07-26T14:57:39.117 に答える