Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Ios 平移动作未完成时的周期性事件';t结束_Ios_Objective C_Uigesturerecognizer_Uipangesturerecognizer - Fatal编程技术网

Ios 平移动作未完成时的周期性事件';t结束

Ios 平移动作未完成时的周期性事件';t结束,ios,objective-c,uigesturerecognizer,uipangesturerecognizer,Ios,Objective C,Uigesturerecognizer,Uipangesturerecognizer,因此,我当前的项目有一个平移手势识别器,如果我平移到屏幕顶部,屏幕应该向上滚动以说明该手势。虽然手势还没有结束,而且手势的当前位置仍在屏幕顶部,但我希望继续滚动。我的问题是,手势识别器仅在状态更改时才会被调用,因此我的内容只有在顶部来回移动时才会滚动,而不是在手势继续处于顶部时持续滚动。当手势还没有结束,但不一定改变时,有没有合理的方法持续调用代码?以下是我的伪代码: - (void)handleGestureRecognizer:(UIGestureRecognizer *)gesture {

因此,我当前的项目有一个平移手势识别器,如果我平移到屏幕顶部,屏幕应该向上滚动以说明该手势。虽然手势还没有结束,而且手势的当前位置仍在屏幕顶部,但我希望继续滚动。我的问题是,手势识别器仅在状态更改时才会被调用,因此我的内容只有在顶部来回移动时才会滚动,而不是在手势继续处于顶部时持续滚动。当手势还没有结束,但不一定改变时,有没有合理的方法持续调用代码?以下是我的伪代码:

- (void)handleGestureRecognizer:(UIGestureRecognizer *)gesture {
    if ( gesture.state == UIGestureRecognizerStateChanged ) {
        CGPoint point = [gesture locationInView:self.view];
        if (point.y < 100) {
            //I would like this code to be called continually while the
            //gesture hasn't ended, not necessarily only when it changes
            [self updateScrollPosition];
        }
}
-(void)HandlegestureRecognitor:(UIgestureRecognitor*)手势{
如果(手势.state==UIGestureRecognitizerStateChanged){
CGPoint point=[手势位置视图:self.view];
如果(点y<100){
//我希望在
//手势并没有结束,不一定只有在它改变的时候才结束
[自更新滚动位置];
}
}

我可以根据识别器的当前状态设置状态布尔值,并创建自己的计时器来定期检查,这是犹太人区的几种方法,但它似乎很粗糙,我并不特别喜欢,所以我想知道是否有人能想出一个更干净的解决方案。

使用计时器并感觉更好的一种方法是be使用performSelector:withObject:afterDelay稍微隐藏它:

- (void)stillGesturing {
    [self updateScrollPosition];
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    [self performSelector:@selector(stillGesturing) withObject:nil afterDelay:0.5];
}

// then in the recognizer target
if (gesture.state == UIGestureRecognizerStateEnded) {
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
} else if ( gesture.state == UIGestureRecognizerStateChanged ) {
    CGPoint point = [gesture locationInView:self.view];
    if (point.y < 100) {
        //I would like this code to be called continually while the
        //gesture hasn't ended, not necessarily only when it changes
        [self stillGesturing];
    }
}
-(无效)仍然做手势{
[自更新滚动位置];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self-performSelector:@selector(Stillgesting)with object:nil afterDelay:0.5];
}
//然后在识别器目标中
如果(手势.state==UIGestureRecognitizerStateEnded){
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}else if(signature.state==UIgestureRecognitizerStateChanged){
CGPoint point=[手势位置视图:self.view];
如果(点y<100){
//我希望在
//手势并没有结束,不一定只有在它改变的时候才结束
[自我静止手势];
}
}

在不确定的情况下,尝试类似于..if(signature.state!=UIgestureRecognitizerEnded&&point.y我正要建议使用计时器,然后我读到了“ghetto”:-),但我认为sdk手势到处使用计时器,只是隐藏在应用程序之外,这并不是一个贫民区。它可能有点冗长,但我认为计时器是一个不错的方式。如果手势结束时方法正在执行,这不会导致竞争条件吗?还有,在关闭ca中,是否仍有目标选择器取消se我还有其他选择器可以调用吗?没有竞争条件,主队列将序列化(并且在清除之前,静止手势不会让新消息队列排队),但是是的,这将不加区别地取消任何其他延迟的执行。(一个适当的计时器将允许您进行选择,我只是试图隐藏犹太人区)要执行正确的计时器,只需将perform替换为schedule,将cancelPrev替换为invalidate。(您需要将其保留在属性中,以便在手势结束时使其无效).是的,看看计时器代码,我想它并没有我想象的那么难看,也不需要我添加任何状态变量,只需在最后使计时器无效,我想这就是我最终要做的。谢谢你的回答!