简体   繁体   English

UISwipeGestureRecognizer叫了两次?

[英]UISwipeGestureRecognizer called twice?

I'm having problem with UISwipeGestureRecognize called twice, I created tabbarcontroller based application which having 4 tabs. 我有两次调用UISwipeGestureRecognize的问题,我创建了基于tabbarcontroller的应用程序,它有4个选项卡。 Each tab having UINavigationController under that UIViewController, there i have impelemented below code in 3rd tab. 每个选项卡在UIViewController下都有UINavigationController,我在第3个选项卡中有下面的代码。

UISwipeGestureRecognizer *swipeLeft =[[UISwipeGestureRecognizer alloc]
        initWithTarget:self action:@selector(didSwipeLeft:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];

- (void) didSwipeLeft:(UISwipeGestureRecognizer *)sender {
    NSLog(@"Left..");
    if ((sender.state == UIGestureRecognizerStateEnded)) {
        [self.tabBarController setSelectedIndex:0];
    }
}

When i do left swipe in simulator, it is calling "didSwipeLeft" when control reaching [self.tabBarController setSelectedIndex:0] line, the function (didSwipeLeft) calling again. 当我在模拟器中离开滑动时,当控制到达[self.tabBarController setSelectedIndex:0]行时,它正在调用“didSwipeLeft”,该函数(didSwipeLeft)再次调用。 Please help me, how to resolve the problem, Is anyone have faced same problem. 请帮帮我,如何解决问题,是否有人遇到同样的问题。 Thanks in Advance. 提前致谢。

I had this kind of problem with UIImagePickerController, and I solve it with an static int. 我有UIImagePickerController的这种问题,我用静态int解决它。 Punt an static int or bool and reset it in view will appear and in in didSwipeLeft set it, and do the action only your static is not set. Punt一个静态int或bool并在视图中重置它将出现并在didSwipeLeft设置它,并执行操作只有你的静态没有设置。 Hope that helps. 希望有所帮助。

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

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