Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone ios中的手势识别器_Iphone_Ios_Uigesturerecognizer - Fatal编程技术网

Iphone ios中的手势识别器

Iphone ios中的手势识别器,iphone,ios,uigesturerecognizer,Iphone,Ios,Uigesturerecognizer,我在LongtapgestureRecognitor中有以下代码,用于自动滚动视图: -(void) longPressDetectedgesture: (UILongPressGestureRecognizer*)recognizer { _btnautoscrollstop.hidden = NO; _btnautoscroll.hidden = YES; // if (autoscrollTimer == nil) { autoscro

我在LongtapgestureRecognitor中有以下代码,用于自动滚动视图:

-(void) longPressDetectedgesture:
        (UILongPressGestureRecognizer*)recognizer
{
    _btnautoscrollstop.hidden = NO;
    _btnautoscroll.hidden = YES;

    // if (autoscrollTimer == nil) { 

    autoscrollTimer = [NSTimer 
        scheduledTimerWithTimeInterval:(55.0/1000.0) 
        target:self 
        selector:@selector(autoscrollTimerFired:)  
        userInfo:nil  
        repeats:YES]; 
}
- (void)autoscrollTimerFired:(NSTimer*)timer { 
    CGPoint scrollPoint = self.table.contentOffset; 
    scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1); 
    [self.table setContentOffset:scrollPoint animated:NO]; 
}

它非常适合我,但我需要的是,当用户第二次点击屏幕进行长手势时,自动crooling必须停止,反之亦然。当用户再次点击时,如何停止此操作。

看起来您就快到了。你可能想要这样的东西:

if (recogniser.state == UIGestureRecognizerStateBegan) {
    if (autoscrollTimer == nil) { 
        autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(55.0/1000.0) 
                                                           target:self 
                                                         selector:@selector(autoscrollTimerFired:)  
                                                         userInfo:nil  
                                                          repeats:YES];
    } else {
        [autoscrollTimer invalidate];
        autoscrollTimer = nil;
    }
}

我通常做的是声明一个全局布尔变换;并将其初始化为Alter=NO;在viewDidLoad(或任何其他方法)中


在viewDidLoad或类似文件中创建一个名为shouldFireTimer的BOOL,并在每次检测到长按时更新其值

-(void) longPressDetectedgesture: (UILongPressGestureRecognizer*)recognizer {
    _btnautoscrollstop.hidden = NO;
    _btnautoscroll.hidden = YES;
    if ( shouldFireTimer ) {
        [autoscrollTimer invalidate];
        autoscrollTimer = nil;
    } else {
        autoscrollTimer = [NSTimer 
            scheduledTimerWithTimeInterval:(55.0/1000.0) 
            target:self 
            selector:@selector(autoscrollTimerFired:)  
            userInfo:nil  
            repeats:YES]; 
    }
    shouldFireTimer = !shouldFireTimer;
}

- (void)autoscrollTimerFired:(NSTimer*)timer { 
     CGPoint scrollPoint = self.table.contentOffset; 
     scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1); 
     [self.table setContentOffset:scrollPoint animated:NO]; 
}

或者像马特上面说的,可能只是检查nil状态,而不是使用BOOL。我建议使用BOOL,因为在其他情况下(例如,从按钮)也可能触发autoscrollTimerFired,也就是说,当你想调用它时,它可能不是nil

@mvds我尝试了很多方法来实现这一点,但是没有运气我把-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{NSUInteger numTaps=[[toucheanyobject]tapCount];if(numTaps==2){在这里面,我放了停用时间代码,但没有lucki放你的代码,但是当我松开手指时,它没有滚动,只有当我继续点击屏幕时才会自动搜索,而当我松开时,它停止了。只需要检查它处于什么状态。当状态变为
UIgestureRecognitizerStateEnded或其他什么。我相信你能想出办法。那么你到底想做什么?你是如何创建手势识别器的?按照我的建议做一些事情绝对是正确的。为什么你要这样做,而不仅仅是使用if
autoscrollTimer
is
nil
,但是它有什么好处呢当您在
autoscrollTimer
中已经有一个随机的额外标志时,您可以使用该标志吗?因为除了长按检测之外,他可能还在其他地方设置计时器?
-(void) longPressDetectedgesture: (UILongPressGestureRecognizer*)recognizer {
    _btnautoscrollstop.hidden = NO;
    _btnautoscroll.hidden = YES;
    if ( shouldFireTimer ) {
        [autoscrollTimer invalidate];
        autoscrollTimer = nil;
    } else {
        autoscrollTimer = [NSTimer 
            scheduledTimerWithTimeInterval:(55.0/1000.0) 
            target:self 
            selector:@selector(autoscrollTimerFired:)  
            userInfo:nil  
            repeats:YES]; 
    }
    shouldFireTimer = !shouldFireTimer;
}

- (void)autoscrollTimerFired:(NSTimer*)timer { 
     CGPoint scrollPoint = self.table.contentOffset; 
     scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1); 
     [self.table setContentOffset:scrollPoint animated:NO]; 
}