我正在用UITapGestureRecognizer翻开漫画书的一页。当我按下水龙头时,我发送:
[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完成递增,然后重置为零。
请帮帮我!我想不出如何阻止tapCount递增到超过1。
发布于 2012-02-16 13:34:47
[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
}
}发布于 2012-02-16 22:11:38
我不想使用UIView的beginAnimations:方法,所以再次尝试了使用块的新方法。我以前尝试过&不知道这次我做了什么不同,但结果是有利的。
我发现,当我使用这个方法设置滚动视图的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");
}];
}
}https://stackoverflow.com/questions/9306009
复制相似问题