0

我在我的收藏视图中使用 UILongPressGestureRecognizer,我希望长按手势识别器只有在满足特定条件时才能工作。

NSString *check;
if([check isEqualToString:@"Enabled"]
{
    //long press should be detected. or following method should be called
}

-(void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer

{
}
4

2 回答 2

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;
    }
}
于 2016-07-12T06:04:28.030 回答
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

{

}
于 2016-07-12T08:11:37.730 回答