我想在单击一个类的对象时删除手势识别器

时间:2015-05-06 06:59:08

标签: ios objective-c

我想在点击课程对象时删除手势。

从我这边我会尝试下面的代码,但它不起作用。请帮帮我

- (void) registerGesture
    {
       UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouch:)];
       tapGesture.numberOfTapsRequired = 1;
       [self.view addGestureRecognizer:tapGesture];
    }
    - (void) handleTouch:(UITapGestureRecognizer *) gesture
        {
           CGPoint touchPoint = [gesture locationInView:self.view];

           NSArray *viewsAtPoint = [self viewsAtPoint:touchPoint];

           for(TheifView * aView in viewsAtPoint)
           {
             [aView removeFromSuperview];
           }
        }
    - (NSArray *) viewsAtPoint:(CGPoint) point
    {
        NSArray *subViews = [self.view subviews];
        NSMutableArray *viewsAtPoint = [NSMutableArray new];

        for(UIView *theView in subViews)
        {
            if([theView isKindOfClass:[TheifView class]])
            {
                TheifView *theif = (TheifView *) theView;

                CGPoint convertedPoint = [theif convertPoint:point fromView:self.view];
                if([theif pointInside:convertedPoint withEvent:nil])
                {
                    [viewsAtPoint addObject:theif];
                }
            }
        }

        return viewsAtPoint;
    }

1 个答案:

答案 0 :(得分:1)

您可以使用UIGestureRecogonizerDelagte方法删除手势

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    if ([self.panGestureRecognizer isEqual:gestureRecognizer]) {

    }
    return YES;
}  

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {


    return NO;
}