2011-07-01 49 views
3

我有一個全屏大小(iPad,1024x768,橫向模式)的UIScrollView。所以我需要用兩根手指在它上面的任何方向識別。這就是我有(mainScroll是我班的財產):礦石UIScrollView滑動識別兩個觸摸

//MyViewController.h 
- (void)loadView { 
    mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; 
    mainScroll.contentSize = CGSizeMake(1024*pageNumber, 768); 
    mainScroll.pagingEnabled = YES; 
    mainScroll.delegate = self; 
    [self.view addSubview:mainScroll]; 

    GestureRecognizer *tapInterceptor = [[GestureRecognizer alloc] init]; 
    tapInterceptor.numberOfTouchesRequired = 2; 
    tapInterceptor.direction = UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight; 
    [mainScroll addGestureRecognizer:tapInterceptor]; 
    mainScroll.userInteractionEnabled = YES; 
} 

//GestureRecognizer.h 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    if ([touches count] > 1) 
     NSLog(@"Started"); 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    if ([touches count] > 1) 
     NSLog(@"Moved"); 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    if ([touches count] > 1) 
     NSLog(@"Ended"); 
} 

我不得不添加條件

if ([touches count] > 1) 

,因爲它的作品不僅爲兩(更多)觸動,但也是一個。

但刷卡(有兩個觸摸)仍然滾動我的UIScrollView。我如何防止它?那麼如何才能識別刷卡而不會對我的scrollView產生任何影響?

+2

哈哈。大聲笑。標題 !! – Legolas

+0

那麼你的編程問題是什麼?請明確點。 – ryanprayogo

+0

問題是:我怎樣才能識別刷卡沒有任何影響我的scrollView? – demon9733

回答

2

的UIGestureRecognizer的文檔給每個以下三個特性的一個很好的解釋:

cancelsTouchesInView - 如果一個手勢識別器識別出它的姿態,它取消綁定手勢的剩餘觸摸從他們的觀點(所以該窗口不會傳遞它們)。該窗口用(touchesCancelled:withEvent :)消息取消先前傳遞的觸摸。如果手勢識別器無法識別其手勢,則視圖會接收多點觸摸序列中的所有觸摸。

delaysTouchesBegan - 只要手勢識別,分析觸摸事件時,未發生故障識別其手勢,窗口截留在UITouchPhaseBegan相所附視圖觸摸對象的遞送。如果手勢識別器隨後識別其手勢,則視圖不接收這些觸摸對象。如果手勢識別器無法識別其手勢,則窗口會在調用視圖的touchesBegan:withEvent:方法(並可能跟隨touchesMoved:withEvent:調用以通知其觸摸當前位置)中傳遞這些對象。

delaysTouchesEnded - 只要手勢識別,分析觸摸事件時,未發生故障識別其手勢,窗口截留在UITouchPhaseEnded相所附視圖觸摸對象的遞送。如果手勢識別器隨後識別其手勢,則觸摸被取消(在touchesCancelled:withEvent:消息中)。如果手勢識別器無法識別其手勢,則窗口在調用視圖的touchesEnded:withEvent:方法時傳遞這些對象。

這裏有很多:UIGestureRecognizer

我在想你要麼「delaysTouchesBegan」或「delaysTouchesEnded」,以便滾動視圖不會收到任何觸摸(IE滾動視圖),直到手勢失敗的要求。