【问题标题】:Detect long tap in UIScrollView在 UIScrollView 中检测长按
【发布时间】:2010-04-06 14:21:16
【问题描述】:

如何检测 UIScrollView 中的长按(长按)?

【问题讨论】:

    标签: iphone cocoa-touch iphone-sdk-3.0


    【解决方案1】:

    在视图的touchesBegan: 中,您可以稍稍延迟调用您的“长按”句柄。

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

    然后在视图的touchesEnded: 中,如果没有足够的时间,您可以取消该调用:

    [NSObject cancelPreviousPerformRequestsWithTarget:touchHandler selector:@selector(longTap:) object:nil];
    

    【讨论】:

      【解决方案2】:
      //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");
      
          }
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多