Developer
Developer

Reputation: 832

Detect LongPress when certain condition is met

I am using UILongPressGestureRecognizer in my collection view, i want long press gesture recogniser should work only if certain condition is met.

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

-(void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer

{
}

Upvotes: 0

Views: 70

Answers (2)

Abd Aboudi
Abd Aboudi

Reputation: 341

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

{

}

Upvotes: 1

Pranav
Pranav

Reputation: 701

Add 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;
    }
}

Upvotes: 1

Related Questions