2012-01-17 10 views
2

私のアプリケーションでは、cameraOverlayViewをカメラキャッチャーに追加しました。それは、2つのサブビュー、2つのUIButtonsと1つのUIImageViewを含んでいます。画像はドラッグ可能です。ボタンは、画像を別の画像に変更するために使用されます。iOSのカメラオーバーレイビュー(カメラキャッチコピーの)で巧妙なタッチ?

私がボタンや画像をタッチすると、カメラのタップ・ツー・フォーカス・レットが常に下に表示され(実際のフォーカスが変わります)。すべての3つのサブビューでexclusiveTouchYESを設定しても、動作は変更されません。

私のオーバーレイビューのボタン/サブビューのタッチを取得するのを止めることができます(ただし、タッチからフォーカス、タッチスクリーンの切り替えなど)。

さらに詳しい情報を入力してください。私は、オーバーレイビューを持っている間にカメラのやりとりを可能にするために、次のコードを使用しています。

// 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

質問に詳細を追加しました。 – calimarkus

答えて

0

これを停止する方法はいくつかあります。どのような方法でも、私がやりたいことはまったくありません。しかし、それを調整することはあなたに何か有用なものを与えるはずです。

1.)カメラの制御を無効にします。 cameraPickerController.showsCameraControls = NO;これは最終的には画面からのフォーカスを得るためにタッチダウンしますが、他のコントロールも減ります。

2.)オーバーレイビューでhitTestを制御し、その領域をnilに設定します。このソリューションは非常に扱いにくいですが、私にとってはうまくいきます。

これは微調整を取得するのであれば、これはあなたのために働くだろう顔は

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

をマスクする管理私のoverlayViewです。私はまだすべてのハッキングなしでこの仕事をする魔法の杖を探しています。まだそれの兆候はありません:(

関連する問題