2016-07-12 4 views
0

コレクションビューでUILongPressGestureRecognizerを使用しています。長いプレスのジェスチャ認識機能が一定の条件を満たす場合にのみ動作します。特定の条件が満たされたときにLongPressを検出します。

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

-(void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer 

{ 
} 

答えて

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; 
    } 
} 
+0

'shouldRecognizeSimultaneouslyWithGestureRecognizer'は、この目的のために使用することはできませんを追加します。 gestureRecognizerShouldBeginは正しいものです。 –

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 

{ 

} 
関連する問題