首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在选项卡式视图应用程序中滑动手势

在选项卡式视图应用程序中滑动手势
EN

Stack Overflow用户
提问于 2012-07-13 03:10:09
回答 1查看 4.3K关注 0票数 0

所以这非常非常奇怪。我已经为我的6个选项卡栏中的第一个选项卡添加了一个从右板到视图的滑动手势识别器。我将其设置为左方向,并将其作为Action连接到firstTabViewController.h。而且它工作得很完美。

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

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

firstTabViewController.h

代码语言:javascript
运行
复制
- (IBAction)swipeLeft:(id)sender;   // Works fine
- (IBAction)swipeRight:(id)sender;  // Doesn't even register

firstTabViewController.m

代码语言:javascript
运行
复制
- (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");
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-13 03:28:19

我刚刚测试了一下,它工作正常:

代码语言:javascript
运行
复制
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");

}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11458918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档