ios - 如何停止处理手势

标签 ios gesture

在我的应用程序中,我有一个 tapGesture、panGesture、rotationGesture 和 pinchGesture。 tapGesture 是所有手势的起点,它向我展示了选择了哪个 subview 。

当我输入一个按钮来处理 ImagePicker 后, subview 仍然处于选中状态,因此它仍在处理手势。

我的问题:是否有停止处理手势的声明?

编辑

我不需要 gestureRecognizer,因此我将它们置于非事件状态:

panRecognizer.enabled = NO;
pinchRecognizer.enabled = NO;
rotationRecognizer.enabled = NO;

因此,如果我需要它们,我希望在处理 tapRecognizer 时让它们工作, 但此处识别器不会从非事件状态变为事件状态。

[panRecognizer isEnabled];
pinchRecognizer.enabled = YES;
rotationRecognizer.enabled = YES;

编辑

我的 View 是一个 ViewController, subview 在 imageView 上。
识别器被分配给 self.imageView。
在第一种方法中,我禁用了识别器,在第二种方法中,我启用了它们

- (IBAction)photo: (id) sender {

    panRecognizer.enabled = NO;
    pinchRecognizer.enabled = NO;
    rotationRecognizer.enabled = NO;

    UIImagePickerController* picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.allowsEditing = NO;

    @try {

        picker.sourceType=UIImagePickerControllerSourceTypeCamera;
        [self presentModalViewController:picker animated:YES];
    }
    @catch (NSException * e) {

        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Camera is not available" 
                                                        delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
        [alert show];
    }
    [picker release];
}

- (IBAction)oneTap: (UIGestureRecognizer*)gestureRecognizer { 
    NSLog(@"oneTap");
    float differenz = 2000;
    [panRecognizer isEnabled];
    pinchRecognizer.enabled = YES;
    rotationRecognizer.enabled = YES;

    for (UIView* const subview in array) {  
        subview.opaque = YES;
        CGPoint const point = [gestureRecognizer locationInView:self.imageView];

            float zwischenS = sqrt(powf(point.x - subview.frame.origin.x,2)) + sqrt(powf(point.y - subview.frame.origin.y,2));


            if (differenz > zwischenS ) {

                differenz = sqrt(powf(point.x - subview.frame.origin.x,2)) + sqrt(powf(point.y - subview.frame.origin.y,2));
                newView.layer.borderColor = [[UIColor clearColor]CGColor];
                newView = subview;

                subview.layer.borderColor = [[UIColor whiteColor]CGColor];
                subview.layer.borderWidth = 3.0f;
                [imageView bringSubviewToFront: subview]; 
            } 
    }
} 

我的错误是什么?

提前致谢

最佳答案

属性[启用UIGestureRecognizer]

关于ios - 如何停止处理手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10329355/

相关文章:

swiftui - 获得阻力速度的最佳方法是什么?

Flutter PhotoView - 围绕手指之间的点旋转

android - 检测指纹传感器上的手势-Android

android - 判断 Android P 手机是否使用手势或导航栏

ios - 无法在 Swift 3.0 中将 CIImage 转换为 UIImage

ios - 我可以在自定义 uitableviewcell 中使用滑动删除功能吗?

ios - 添加和删​​除标记时重新加载 Google map View

java - 是否可以覆盖自定义 ImageView?

ios - Swift:为什么三元运算符创建数组的副本而不是引用原始数组?

ios - OCMock传递任何CGSize