gpt4 book ai didi

ios - 在 xCode obj 中实现滑动手势。 C

转载 作者:行者123 更新时间:2023-11-29 11:43:52 27 4
gpt4 key购买 nike

我在 Objective C 编程方面相当陌生,我正在尝试实现滑动手势以在我在 Xcode 中创建的应用程序的 View Controller 之间滑动。我试图做到这一点,所以当我向左滑动时,它会切换到另一个我命名为“SecondViewController”的 View Controller 。我在我的 .h 文件中为我的手势创建了导出和 Action ,并在我的 .m 文件中添加了以下代码:

- (IBAction)swipeLeft:(id)sender {

ViewController *SecondViewController = [[ViewController alloc] init];
[self presentViewController:SecondViewController animated:YES
completion:nil];

每当我运行该应用程序时,滑动时没有任何反应。有什么我还没有做的,我需要做的才能完成这项工作吗?

最佳答案

基本上有四种滑动手势可用:

UISwipeGestureRecognizerDirectionRight
UISwipeGestureRecognizerDirectionLeft
UISwipeGestureRecognizerDirectionUp
UISwipeGestureRecognizerDirectionDown

您可以根据需要使用其中的任何一个。要添加上述任何手势,您可以分配手势,然后将其添加到您的特定 View 。因此,一旦检测到您滑动,它就会调用相关方法。

例如左右手势:

 UISwipeGestureRecognizer *gestureRecognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)];
[gestureRecognizerRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.view addGestureRecognizer:gestureRecognizerRight];

UISwipeGestureRecognizer *gestureRecognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)];
[gestureRecognizerLeft setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:gestureRecognizerLeft];

-(void)swipeHandlerRight:(id)sender
{
}

-(void)swipeHandlerLeft:(id)sender
{
}

关于ios - 在 xCode obj 中实现滑动手势。 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45047650/

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