我在两次调用 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)再次调用。请帮助我,如何解决问题,是否有人遇到过同样的问题。提前致谢。