2012-02-16 48 views
0

我正在使用UITapGestureRecognizer來打開漫畫書頁面。當我把水龍頭,我送:iOS - 設置MAXIMUM touchCount

[comicScrollView setContentOffset:CGPointMake(nextPageCGPoint) animated:YES]; 

- 換句話說,在輕擊事件我的動畫內容的滾動視圖的偏移量,顯示在滾動視圖中的下一個頁面。

問題是,除非動畫完成,否則我不想讓其他輕擊手勢影響contentOffset。問題是,在實踐中,我發現這非常困難 - 我已經嘗試在設置內容偏移量之前將「isAnimating」布爾值設置爲YES,然後使用回調將其設置爲NO;我嘗試過設置動畫:完成: - 但每次輕敲進入時,tapCount都會增加。

如下:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 
    NSLog(@"%d", [touch tapCount]); 
} 

經常不斷遞增tapCount因爲我點擊它,如果我把這個成方法:

if ([touch tapCount] > 1) { [gestureRecognizer setEnabled:NO]; } 

不會禁止手勢識別,直到後tapCount已經完成增量&然後重置爲零。

請幫忙!我無法弄清楚如何從過去增加1

回答

0
[UIView beginAnimations:@"AnimateIn" context:nil]; 
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; 
[UIView setAnimationDuration: 0.7f]; 

//Add this 
[UIView setAnimationDelegate:self]; 

[UIView setAnimationDidStopSelector:@selector(loadingViewDisappear:finished:context:)]; 
loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height); 
[UIView commitAnimations]; 



- (void)loadingViewDisappear:(NSString *)animationID finished:(NSNumber *) finished context:(void *) context { 
    NSLog((finished ? @"YES!" : @"NO!")); 
    if ([animationID isEqualToString:@"AnimateIn"] && finished) { 
     //do something here 
    } 
} 
+0

感謝您爲我設置正確的道路 - 我又看了一下[...動畫:completion:]方法,並按照我的第二篇文章中的描述進行了計算。 – jankins 2012-02-16 14:23:14

0

我不想用停止tapCount [UIView的beginAnimations:]的方法,因此使用塊新的方式再次嘗試。我之前試過這個,&不知道我這次做了什麼不同,但結果是有利的。

我發現,當我使用這種方法設置scrollview的contentOffset時,即使我的tapCount仍然在遞增,只要我繼續像瘋子一樣敲擊,頁面現在就會以期望的行爲進行動畫製作,而不是不規律。就好像它不讓我「在另一個動畫上粘貼」。這正是我想要的行爲。

-(void)singleTap:(UITapGestureRecognizer*)tapRecognizer { 

    CGPoint tapLocation = [tapRecognizer locationInView:self.view]; 

    //a tap on the right side turns to the next page: 
    if (tapLocation.x > self.view.frame.size.width/2) { 
     [UIView animateWithDuration:.3 animations:^{ 
      [comicScrollView setContentOffset:nextPagePoint]; 
     }completion:^(BOOL finished){ 
      NSLog(@"finished"); 
     }]; 
    } 
}