我正在添加多个带有平移手势的标签,并在每个标签上点按手势。但是,当我点按任何标签时,平移手势是否没有从其他标签中移除?
- (void)oneTap:(UITapGestureRecognizer *)gesture {
tapedLabel=gesture.view.tag;
//NSLog(@" tapped label is %d",numberOfLabel);
//add pangesture
self.pangesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)] ;
[self.pangesture setMinimumNumberOfTouches:1];
[self.pangesture setMaximumNumberOfTouches:1];
[ self.pangesture setDelegate:self];
for(int i=1;i<=numberOfLabel;i++)
{
UILabel *label=[self.labelDict objectForKey:[NSString stringWithFormat:@"%d",i]];
label.userInteractionEnabled=YES;
if(i==tapedLabel)
{
//NSLog(@"i value %i tag value %d",i,tapedLabel);
[label addGestureRecognizer:self.pangesture];
// NSLog(@"remove gesture over label %@",label);
}
else
{
//NSLog(@"i value %i tag value %d",i,tapedLabel);
[label removeGestureRecognizer:self.pangesture];
NSLog(@"add gesture over label %@",label);
}
}
}
答案 0 :(得分:0)
让我们试试这个删除你的panGesture,
如果您有两个标签手势,请使用以下内容。
if (label.gestureRecognizers.count > 1)
[label removeGestureRecognizer:[label.gestureRecognizers lastObject]];