2014-03-24 53 views
1

我已經設法改變UISwipeGestureRecognizer的意見,但它只是在我完成刷卡後開始改變視圖。當我開始在屏幕上拖動我的手指時,如何才能使它開始?我搜索了但找不到答案。刷卡XCode的實時反饋

回答

-1

手勢識別器將等待,直到確定做出了哪個手勢。這就是爲什麼他們總是有一點延遲。這樣做的一種方法是實現您自己的滑動處理程序。例如。您可以使用touchesBegan:touchesEnded:touchesMoved:和TouchesCancelled: - 方法。

(記住啓用userInteractionEnabled屬性的節點(S),以使這些方法)

// SKScene init 
{ 
    self.userInteractionEnabled = YES; 
} 

- (void) touchesBegan:(NSSet*) touches withEvent:(UIEvent*)event 
{ 
    // register that touch(es) began 
} 

- (void) touchesMoved:(NSSet*) touches withEvent:(UIEvent*)event 
{ 
    // Calculate which way touch(es) is/are moving 
} 

- (void) touchesEnded:(NSSet*) touches withEvent:(UIEvent*)event 
{ 
    // Register that touch(es) ended 
} 
+0

平移手勢識別器會在您移動手指時不斷給您回電。 – rounak

+0

而我從未說過它不會。我只是注意到(某些)手勢識別器(如滑動)在觸發之前總會有一點延遲。這就是爲什麼他們可能不適合需要即時反饋的情況。 實際上,您可以使用PanGestureRecognizer實現您自己的滑動手勢。我只是提出了另一種註冊觸摸的方法。 – JKallio

2

使用全景手勢

 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; 
    [self addGestureRecognizer:pan]; 

然後做:

- (void)handlePan:(UIPanGestureRecognizer *)gesture { 

    CGPoint touchPoint = [gesture locationInView:YOUR_VIEW]; 
    UIView *draggedView = [gesture view]; 

    switch ([gesture state]) { 

     case UIGestureRecognizerStateBegan:  
      break; 

     case UIGestureRecognizerStatePossible: 

      break; 

     case UIGestureRecognizerStateChanged: 
      break; 

     case UIGestureRecognizerStateEnded: 
      break; 

     case UIGestureRecognizerStateCancelled: 
      break; 

     case UIGestureRecognizerStateFailed: 
      break; 

     default: 
      break; 
    } 
}