我在我的集合视图中使用UILongPressGestureRecognizer,我希望长按手势识别器只有在满足某些条件时才能工作。
NSString *check;
if([check isEqualToString:@"Enabled"]
{
//long press should be detected. or following method should be called
}
-(void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer
{
}
答案 0 :(得分:1)
添加UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
NSString *check;
if([check isEqualToString:@"Enabled"]
{
//long press should be detected. or following method should be called
return YES;
}else{
return NO;
}
}
答案 1 :(得分:1)
NSString *check;
UILongPressGestureRecognizer *longPress =[ [UILongPressGestureRecognizer alloc]init];
if([check isEqualToString:@"Enabled"]
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPressGesture:)];
}else{
}
-(void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer
{
}