我想在单击类的对象时删除手势

I want to remove gesture when i click on object of a class

提问人:Arjun Singh Baghel 提问时间:5/5/2015 最后编辑:AnthonArjun Singh Baghel 更新时间:5/8/2015 访问量:213

问:

从我的角度来看,我将尝试以下代码,但它不起作用。

- (void) handleTouch:(UITapGestureRecognizer *) gesture
{
   CGPoint touchPoint = [gesture locationInView:self.view];

   NSArray *viewsAtPoint = [self viewsAtPoint:touchPoint];

   for(TheifView * aView in viewsAtPoint)
   {
     [aView removeFromSuperview];
   }
}


- (void) registerGesture
{
   UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouch:)];
   tapGesture.numberOfTapsRequired = 1;
   [self.view addGestureRecognizer:tapGesture];
}
IOS 的Objective-C iPhone 的iOS7 IOS5

评论

1赞 Dan Getz 5/5/2015
欢迎来到 StackOverflow!请提供“不工作”以外的更具体信息。

答:

-1赞 Savitha 5/5/2015 #1

手势目标和选择器可以通过以下代码删除

[gesture removeTarget:self action:@selector(handleTouch:)];
-1赞 Vidhyanand 5/5/2015 #2

将标签放入 ThiefView...说 111。然后,您可以识别它并从 self.view 中删除。如果这不是您期望的答案,请用清晰的描述进行解释。

用于从视图中删除手势。

for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
            if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]) {
                [self.view removeGestureRecognizer:recognizer];
            }
        }

用于从视图中删除 ThiefView

    for (UIView *subview in self.view.subviews) {
        if (subview.tag==111) {
            [subview removeFromSuperview];
        }
    }
-1赞 souvickcse 5/5/2015 #3

完全删除它

- (void) handleTouch:(UITapGestureRecognizer *) gesture
{
  [self.view removeGestureRecognizer:gesture];
}

删除其目标

- (void) handleTouch:(UITapGestureRecognizer *) gesture
{
  [gesture removeTarget:self action:@selector(handleTouch:)];
}

禁用手势

- (void) handleTouch:(UITapGestureRecognizer *) gesture
{
  gesture.enabled=NO;
}