Swipe 方法被调用两次
我必须在视图控制器中使用滑动功能。 因此,每当我滑动时,我的滑动方法都会被调用两次,并且我在 (swipe:) 方法中编写的 NSlog 会显示内容两次。
这是我使用过的代码。
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");
}
请告诉我只调用一次需要做什么。
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.
Here is the code which i have used.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是应该发生的事情。您需要查看
state
属性,您可以在其中找到类似的内容UIGestureRecognizerStateBegan
和UIGestureRecognizerStateEnded
。That's what's supposed to happen. You need to look at the
state
property where you'll find things likeUIGestureRecognizerStateBegan
andUIGestureRecognizerStateEnded
.试试这个,识别器有各种状态,例如
Try this, recognizer has various state like