3

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

4

1 回答 1

1

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

于 2011-01-03T14:23:15.577 回答