繁体   English   中英

满足特定条件时检测LongPress

[英]Detect LongPress when certain condition is met

我在集合视图中使用UILongPressGestureRecognizer,我希望长按手势识别器仅在满足特定条件时才能工作。

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

-(void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer

{
}

添加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;
    }
}
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

{

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM