繁体   English   中英

在UIScrollView中检测长按

[英]Detect long tap in UIScrollView

如何在UIScrollView中检测到长按(点击并按住)?

在视图中触摸开始touchesBegan:你可以稍微调用你的“长按”手柄。

[touchHandler performSelector:@selector(longTap:) withObject:nil afterDelay:1.5];

然后在视图的touchesEnded:如果时间不够,你可以取消该通话:

[NSObject cancelPreviousPerformRequestsWithTarget:touchHandler selector:@selector(longTap:) object:nil];
//Add  gesture to a method where the view is being created. In this example long tap is added to tile (a subclass of UIView):

    // Add long tap for the main tiles
    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
    [tile addGestureRecognizer:longPressGesture];
    [longPressGesture release];

-(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer{
    NSLog(@"gestureRecognizer= %@",gestureRecognizer);
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        NSLog(@"longTap began");

    }

}

暂无
暂无

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

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