ECSlidingViewController传递UILongPressGestureRecognizer

时间:2015-11-01 19:31:56

标签: ios objective-c ecslidingviewcontroller

我四处寻找解决方案,但没有人回答我的问题。因此,我从我的项目中退了一步,试图找出这个功能。我正在使用AppDelegate来帮助我更清楚地看到代码。

当用户触摸并按住屏幕时,我希望菜单滑出。当用户松开触摸时它应该向后滑动。

但是,我无法发送手势参数。

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                         bundle: nil];
    ScrollViewController *topViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"Scroll"];
    MenuViewController *underLeftViewController = (MenuViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"Menu"];

    ECSlidingViewController *slidingViewController = [[ECSlidingViewController alloc] initWithTopViewController:topViewController];
    slidingViewController.underLeftViewController = underLeftViewController;

    [slidingViewController.view addGestureRecognizer:slidingViewController.panGesture];
    self.window.rootViewController = slidingViewController;

    // HOW DO I PASS GESTURE DATA?

    UILongPressGestureRecognizer *revealMenuRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:slidingViewController.underLeftViewController action:@selector(revealMenu:  GESTURE PARAMETERS?  )];

    [topViewController.view addGestureRecognizer:revealMenuRecognizer];
    return YES;
}

MenuViewController.m

- (void)revealMenu:(UILongPressGestureRecognizer *)longPressRecognizer {
    if (longPressRecognizer.state == UIGestureRecognizerStateBegan) {
        [self.slidingViewController anchorTopViewToRightAnimated:YES];
    } else {
        if (longPressRecognizer.state == UIGestureRecognizerStateCancelled
            || longPressRecognizer.state == UIGestureRecognizerStateFailed
            || longPressRecognizer.state == UIGestureRecognizerStateEnded)
        {
            [self.slidingViewController resetTopViewAnimated:YES];
        }
    }
}

1 个答案:

答案 0 :(得分:0)

应为action:@selector(revealMenu:)];放置冒号足以让手势识别器将UIGestureRecognizer对象传递给动作。阅读UIGestureRecognizer参考指南

  

调用的操作方法必须符合以下之一   签名:

     
      
  • (无效)handleGesture;
  •   
  • (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;
  •   
     

符合后一种签名的方法允许某些目标   查询发送消息的手势识别器的案例   附加信息。例如,目标可以询问a   UIRotationGestureRecognizer对象的旋转角度(in   自从最后一次调用action方法以来   手势。

如果您不关心对象,请关闭冒号,如果您需要数据,请将其包括在内。你想要后者。