2013-02-06 27 views
1

我可以在touchesMoved中检测到幻灯片动作,但我想知道如何检测幻灯片,然后检测幻灯片何时停止但手指仍然按在屏幕上?在touchesMoved中,如何检测幻灯片动作然后停止?

这里是我到目前为止的代码:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

if(self.tutorialView.alpha != 1.0 || self.tutorialView.hidden) 
{ 

UITouch *touch = [touches anyObject]; 
CGPoint gestureEndPoint = [touch locationInView:self.view]; 

int dx = abs(gestureStartPoint.x - gestureEndPoint.x); 
int dy = -1 * (gestureEndPoint.y - gestureStartPoint.y); 

if(dx > 20) { 
    // too much left/right, so don't do anything 
    return; 
} 

if((gestureStartPoint.x - gestureEndPoint.x) < 20 && (gestureStartPoint.x - gestureEndPoint.x) > -20) 
{ 

    if((gestureStartPoint.y - gestureEndPoint.y) > (gestureStartPoint.x - gestureEndPoint.x)) 
    { 

     if(dy > 0) 
     { 

      // User has made an upwards slide motion 

     } 

     else 
     { 

      // User has made a downwards slide motion 

    else 
     self.number = 0; 

    } 

    } 

} 

} 

} 

回答

4

可以使用定时器,在touchesMoved,无效老计时器,并创建一个新的,这将触发“停止运动检测“选择器。

像这样

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    //NSTimer *_timer; // as an iver 
    if (/* check move distance, if big enough */) { 
     [_timer invalidate]; 
     _timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(slideStopped) userInfo:nil repeats:NO]; 
    } 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    [_timer invalidate]; // you may handle touch up differently and don't want slideStopped get called 
    _timer = nil; 
} 

- (void)slideStopped { 
    // handle slide stopped event 
} 
0

当运动停止下面的方法将被调用。所以你可以在这里跟踪它。

- (无效)touchesEnded:(NSSet中*)触及withEvent:方法(的UIEvent *)事件

+0

不,那是当你把你的手指* *关闭屏幕。我想要检测手指在屏幕上但在滑动移动后不移动。 –