Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在Xcode中向下滑动以关闭当前页面_Objective C_Iphone_Xcode_User Interface_Uiswipegesturerecognizer - Fatal编程技术网

Objective c 如何在Xcode中向下滑动以关闭当前页面

Objective c 如何在Xcode中向下滑动以关闭当前页面,objective-c,iphone,xcode,user-interface,uiswipegesturerecognizer,Objective C,Iphone,Xcode,User Interface,Uiswipegesturerecognizer,所以我写了这行代码来关闭当前的教程页面,让用户使用该应用程序,但是当你向下滑动时,教程页面将消失1秒,然后它会回来 因此,我在教程的view controller.m中编写了这些代码行 -(void)swipeHappened:(UISwipeGestureRecognizer *)swipe { NSLog(@"Swipe Occurred"); switch (swipe.direction) { case UISwipeGestureRecognizerD

所以我写了这行代码来关闭当前的教程页面,让用户使用该应用程序,但是当你向下滑动时,教程页面将消失1秒,然后它会回来

因此,我在教程的view controller.m中编写了这些代码行

-(void)swipeHappened:(UISwipeGestureRecognizer *)swipe
{
    NSLog(@"Swipe Occurred");

    switch (swipe.direction) {
        case UISwipeGestureRecognizerDirectionRight:
            NSLog(@"Right");
            [self dismissViewControllerAnimated:YES completion:nil];
            break;
        case UISwipeGestureRecognizerDirectionLeft:
            NSLog(@"Left");
            break;
        case UISwipeGestureRecognizerDirectionUp:
            NSLog(@"Up");
            break;
        case UISwipeGestureRecognizerDirectionDown:
            NSLog(@"Down");
            break;
    }

}
 -(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];


    TutorialViewController *tutorialViewController=[[TutorialViewController alloc] initWithNibName:@"TutorialViewController" bundle:nil];
    [self presentViewController:tutorialViewController animated:YES completion:NULL];


    //I  HAVE A PROBLEM HERE( there's no error that appears in Xcode but it is not the result I expected 

}
这些都在mainviewcontroller.m中

-(void)swipeHappened:(UISwipeGestureRecognizer *)swipe
{
    NSLog(@"Swipe Occurred");

    switch (swipe.direction) {
        case UISwipeGestureRecognizerDirectionRight:
            NSLog(@"Right");
            [self dismissViewControllerAnimated:YES completion:nil];
            break;
        case UISwipeGestureRecognizerDirectionLeft:
            NSLog(@"Left");
            break;
        case UISwipeGestureRecognizerDirectionUp:
            NSLog(@"Up");
            break;
        case UISwipeGestureRecognizerDirectionDown:
            NSLog(@"Down");
            break;
    }

}
 -(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];


    TutorialViewController *tutorialViewController=[[TutorialViewController alloc] initWithNibName:@"TutorialViewController" bundle:nil];
    [self presentViewController:tutorialViewController animated:YES completion:NULL];


    //I  HAVE A PROBLEM HERE( there's no error that appears in Xcode but it is not the result I expected 

}

有几件事可能是问题所在。首先,MainViewController是TutorialViewController的父级吗?如果是这样的话,那么当您关闭教程并且主控制器调用ViewDidDisplay时,您就是将教程弹回到原位

如果这是问题所在,则需要删除viewDidAppear中显示教程的代码。也许可以将它作为您的第一个控制器从应用程序代理中呈现出来

此外,UISweepGestureRecognizer的direction属性仅用于设置方向,因此您的switch语句可能无法按预期的方式工作。尝试创建一个特定于方向的识别器,如下所示:

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:);
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeRight];
如果您需要对每个方向的滑动做出不同的反应,您应该为每个方向创建四个单独的手势识别器