UISwipeGestureRecognizer 调用了两次?

发布于 2024-10-10 06:38:36 字数 843 浏览 0 评论 0原文

我在调用两次 UISwipeGestureRecognize 时遇到问题,我创建了基于 tabbarcontroller 的应用程序,该应用程序有 4 个选项卡。每个选项卡在 UIViewController 下都有 UINavigationController,我在第三个选项卡中实现了以下代码。

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];
    }
}

当我在模拟器中向左滑动时,当控件到达 [self.tabBarController setSelectedIndex:0] 行时,它会调用“didSwipeLeft”,函数 (didSwipeLeft) 再次调用。 请帮帮我,如何解决这个问题,有没有人遇到过同样的问题。 提前致谢。

I'm having problem with UISwipeGestureRecognize called twice, I created tabbarcontroller based application which having 4 tabs. Each tab having UINavigationController under that UIViewController, there i have impelemented below code in 3rd tab.

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.
Please help me, how to resolve the problem, Is anyone have faced same problem.
Thanks in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抹茶夏天i‖ 2024-10-17 06:38:36

我在使用 UIImagePickerController 时遇到了这种问题,我用 static int 解决了它。
平铺一个静态 int 或 bool 并在视图中重置它将会出现,并在 didSwipeLeft 中设置它,并且仅执行未设置静态的操作。希望有帮助。

I had this kind of problem with UIImagePickerController, and I solve it with an static 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. Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文