将手势添加到UIImagePickerController cameraOverlayView

时间:2017-07-21 15:07:39

标签: ios uiimagepickercontroller uitapgesturerecognizer

我的UIImagePickerController有一个自定义的叠加视图。

我想在此叠加视图中添加UITapGestureRecognizer,以便绘制圆圈并对焦相机。 但是一旦我添加了手势,我的方法就永远不会被调用,我也不明白为什么。

这是我的代码:

// Overlay view
UIView *overlay = [[UIView alloc] initWithFrame:self.view.frame];
// TapGesture
UITapGestureRecognizer *stabilisateurGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Stabiliser:)];
stabilisateurGesture.numberOfTapsRequired = 1;
[overlay addGestureRecognizer:stabilisateurGesture];
// UIImagePickerController
pickerCamera = [[UIImagePickerController alloc] init];
pickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerCamera.delegate = self;
pickerCamera.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
pickerCamera.modalPresentationStyle = UIModalPresentationFullScreen;
pickerCamera.showsCameraControls = NO;
pickerCamera.cameraOverlayView = overlay;

这里是手势方法:

- (void)Stabiliser:(UITapGestureRecognizer *)gesture {
     CGPoint point = [gesture locationInView:gesture.view];
     // Create circle
     UIView *cercleRouge = [[UIView alloc] initWithFrame:CGRectMake(point.x-(86/2), point.y-(86/2), 86, 86)];
     cercleRouge.layer.borderColor = [[UIColor redColor] CGColor];
     cercleRouge.layer.borderWidth = 4;
     cercleRouge.layer.cornerRadius = cercleRouge.frame.size.height/2;
     [gesture.view addSubview:cercleRouge];
}

提前谢谢。

0 个答案:

没有答案