gpt4 book ai didi

ios - 滑动手势识别器对我不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:48 24 4
gpt4 key购买 nike

我正在尝试将 Swipe Gesture Recognizer 添加到我的应用程序中,这样我就可以向左或向右滑动以转到另一个 View Controller 。我将对象拖到我想要的 View Controller ,将其链接起来,这样当向右滑动时它应该将我带到另一个 View Controller 。我运行了模拟器,但滑动功能没有将我带到另一个 View 。

创建新项目时,只需添加 3 个 View Controller 和滑动手势,我就可以在模拟器中滑动,它会将我带到另一个 View Controller 。但是在我当前的应用程序中做完全相同的事情并没有做任何事情。

有什么想法吗?我试过启用/禁用状态,但仍然一无所获

最佳答案

如果您对编写代码感到满意,那么请试试这个。

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

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

现在执行这样的操作:

-(void)PerformAction:(UISwipeGestureRecognizer *)sender {
if(sender.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"RIGHT GESTURE");
// Perform your code here
}

if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"LEFT GESTURE");
// Perform your code here
}
}

如果您想在每个 View Controller 上执行此操作,那么您必须根据当前的 View Controller 设置智能逻辑,以在您的左滑和右滑上执行特定任务。

希望对您有所帮助。

关于ios - 滑动手势识别器对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20596669/

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