首页 文章

如何从Objective-c中的另一个方法调用手势滑动方法

提问于
浏览
1

我有这个手势滑动方法,我想从另一个方法调用

[self performSelector:@selector(handleSwipeGesture :) withObject:nil afterDelay:10];

我无法弄清楚要放入 @selector() 的语法

任何帮助表示赞赏 . 这是我的代码:

- (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender { 
        if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
            NSLog(@"swipe left");
            TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
                                                          initWithNibName:@"TutorialMenuViewController" bundle:nil];
            [self.navigationController pushViewController:tutorialMenuViewController animated:YES];
            [tutorialMenuViewController release];
        }
    }

2 回答

  • 2

    如果你想在手势或时间延迟上呈现 TutorialMenuViewController ,最好只是将其演示文稿抽象为另一种方法

    - (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender { 
        if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
            [self presentTutorial];
        }
    }
    
    - (void)presentTutorial;
    {
        TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
                                                          initWithNibName:@"TutorialMenuViewController" bundle:nil];
        [self.navigationController pushViewController:tutorialMenuViewController animated:YES];
        [tutorialMenuViewController release];
    }
    

    现在你可以简单地打电话

    [self performSelector:@selector(presentTutorial) withObject:nil afterDelay:10];
    
  • 2
    - (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender { 
    if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
        NSLog(@"swipe left");
        //TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
        //                                                        initWithNibName:@"TutorialMenuViewController" bundle:nil];
        //[self.navigationController pushViewController:tutorialMenuViewController animated:YES];
        //[tutorialMenuViewController release];
    }
    }
    

    像这样叫:

    UISwipeGestureRecognizer *leftSwipe  =  [[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil];
    [leftSwipe setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [self performSelector:@selector(handleSwipeGesture:) withObject:leftSwipe afterDelay:1];
    [leftSwipe release];
    

相关问题