开发者

Detect long tap in UIScrollView

开发者 https://www.devze.com 2022-12-26 01:06 出处:网络
How would I detect a long 开发者_JAVA百科tap (tap and hold) within a UIScrollView?In view\'s touchesBegan: you can call your \"long tap\" handle with some delay.

How would I detect a long 开发者_JAVA百科tap (tap and hold) within a UIScrollView?


In view's touchesBegan: you can call your "long tap" handle with some delay.

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

Then in view's touchesEnded: you can cancel that call if not enough time has passed:

[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");

    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消