嘿,伙计们,我在尝试removeGestureRecognizer:
从一个视图时遇到了一个问题,
我想要做的是doubleTap
其中一个imageView
,并删除点击imageView
的singleTap Gesture,而不删除其他imageView
s singleTap Gesture。
以下是我生成视图、手势和机制的方式:
。H
UITapGestureRecognizer *singleTap;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSInteger i;
for (i = 1; i <= 3; i++)
{
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(110, 70+80*(i-1), 100, 60);
imageView.backgroundColor = [UIColor whiteColor];
imageView.tag = i;
imageView.userInteractionEnabled = YES;
[self.view addSubview:imageView];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleMethod:)];
doubleTap.numberOfTapsRequired = 2;
singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleMethod:)];
[singleTap requireGestureRecognizerToFail:doubleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:singleTap];
}
}
- (void)singleMethod: (id)sender
{
NSLog(@"SingleTap");
}
- (void)doubleMethod: (id)sender
{
NSLog(@"%d",[((UITapGestureRecognizer *)sender).view.gestureRecognizers count]);
UIImageView *imageView = nil;
NSArray *tryToFindYou = [self.view subviews];
for (imageView in tryToFindYou)
{
if ([imageView isKindOfClass:[UIImageView class]] && imageView.tag == ((UITapGestureRecognizer *)sender).view.tag)
{
[imageView removeGestureRecognizer:singleTap];
}
}
NSLog(@"%d",[((UITapGestureRecognizer *)sender).view.gestureRecognizers count]);
}
但是我写的这些行无法准确找到附加到双击 imageView 的 singleTap Gesture。
NSLog的时候.gestureRecognizers count
,还是2,去掉的是最后一个imageView
singleTap Gesture,变成了1,没错。
我找不到第一个和第二个,有什么想法可以找到它们吗?谢谢你的阅读:)