滑动方法被调用两次 [英] Swipe Method is getting called twice
本文介绍了滑动方法被调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在视图控制器中使用滑动功能.因此,每当Iam滑动时,我的swipe方法就会被调用两次,而我在(swipe :)方法中编写的NSlog则显示两次内容.
I have to use swipe functionality in my view controller. so, whenever Iam swiping, my swipe method is getting called twice and the NSlogs which I Wrote inside the (swipe:) method is displaying the content two times.
这是我使用的代码.
UIView *swipeView=[[UIView alloc]initWithFrame:CGRectMake(405, 420, 265, 35)];
swipeView.backgroundColor=[UIColor clearColor];
[self.view addSubview:swipeView];
UISwipeGestureRecognizer *gesture;
gesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
[gesture setDirection:(UISwipeGestureRecognizerDirectionRight)];
[swipeView addGestureRecognizer:gesture];
[gesture release];
[swipeView release];
-(void)swipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe received.");
NSLog(@"HIJ");
}
请告诉我我只能打电话一次该怎么做.
please tell me what i have to do for calling it only one time.
推荐答案
尝试一下,识别器具有各种状态,如
Try this, recognizer has various state like
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
-(void)swipe:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded) {
NSLog(@"Swipe received.");
NSLog(@"HIJ");
}
}
这篇关于滑动方法被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文