0

所以这非常非常奇怪。我已将右舷的滑动手势识别器添加到 6 选项卡选项卡栏中的第一个选项卡的视图中。我将其设置为向左方向并将其作为 Action 连接到 firstTabViewController.h。而且效果很好。

现在,如果我尝试以相同的方式将“正确方向”滑动手势识别器添加到第一个选项卡,则该操作甚至不会注册。

此外,如果我尝试在另一个选项卡(不是索引 0 的选项卡)中执行相同的操作,或者将工作选项卡移动到选项卡栏中的不同位置,当我滑动时应用程序会因访问错误而崩溃.

firstTabViewController.h

- (IBAction)swipeLeft:(id)sender;   // Works fine
- (IBAction)swipeRight:(id)sender;  // Doesn't even register

firstTabViewController.m

- (IBAction)swipeLeft:(id)sender {
    int nextIndex = CURRENT_INDEX + 1;  // I did modify this accordingly when the tab was moved

    [self.tabBarController setSelectedIndex:nextIndex];
    NSLog(@"Swipe left");

}

- (IBAction)swipeRight:(id)sender {
    NSLog(@"Swiped Right");
}
4

1 回答 1

3

刚刚测试过它并且它有效:

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

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
swipeRight.delegate = self;
[swipeRight release];

-(void) swipeRight:(UISwipeGestureRecognizer *) recognizer {
    if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
        NSLog(@"swipe right");
}

-(void) swipeLeft:(UISwipeGestureRecognizer *) recognizer {
    if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft)
        NSLog(@"swipe left");

}
于 2012-07-12T19:28:19.203 回答