繁体   English   中英

iOS-设置MAXIMUM touchCount

[英]iOS - set MAXIMUM touchCount

我正在使用UITapGestureRecognizer来翻动漫画书页面。 当我点击水龙头时,我发送:

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

-换句话说,在点击事件中,我会为滚动视图的内容偏移量设置动画,以在滚动视图中显示下一页。

问题是,除非动画完成,否则我不想让另一个轻击手势影响contentOffset。 问题是,在实践中,我发现这非常困难-我尝试在设置内容偏移量之前将“ isAnimating”布尔值设置为YES,然后通过回调将其设置为NO。 我尝试设置animation:completion:-但是每次点击时,tapCount都会递增。

下列:

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

不断增加tapCount的次数,就像我点击它的次数一样,如果我将其放入该方法中:

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

直到tapCount完成递增并重置为零后,它才会禁用手势识别器。

请帮忙! 我不知道如何阻止tapCount超过1。

[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
    }
}

我不想使用[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");
        }];
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM