UISwipeGestureRecognizer 调用了两次?
我在调用两次 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在使用 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.