gpt4 book ai didi

iphone - 在选项卡式 View 应用程序中滑动手势

转载 作者:行者123 更新时间:2023-11-28 20:33:26 24 4
gpt4 key购买 nike

所以这非常非常奇怪。我已经从右舷添加了一个滑动手势识别器到我的 6 标签标签栏中第一个标签的 View 中。我将其设置为向左方向并将其作为 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");
}

最佳答案

刚刚测试了这个并且它有效:

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");

}

关于iphone - 在选项卡式 View 应用程序中滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11458918/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com