如何返回当前的View Controller?

时间:2014-03-10 18:38:50

标签: ios objective-c uiviewcontroller uibarbuttonitem ecslidingviewcontroller

我正在我的应用中实施ECSlidingViewController。一切正常,当我按下菜单按钮(UIBar)时,左侧菜单会滑动。但再次按下菜单按钮不会带回当前的ViewController

它适用于示例应用程序,但我找不到能够带回当前控制器的代码行。

以下是显示菜单的代码:

- (IBAction)menuButtonTapped:(id)sender {
    [self.slidingViewController anchorTopViewToRightAnimated:YES];
}

现在我到处寻找可以解除左侧菜单布局但无法找到它的代码部分。它必须在某处埋葬......

Github project

如何按菜单UIBar按钮?

返回当前的视图控制器

@Eric让我看到了正在表演的事情。似乎UIPanGestureRecognizer是负责重新显示主屏幕的人,遗憾的是我在实现该删除后无法使其工作。

- (UIPanGestureRecognizer *)dynamicTransitionPanGesture {
    if (_dynamicTransitionPanGesture) return _dynamicTransitionPanGesture;

    _dynamicTransitionPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.transitions.dynamicTransition action:@selector(handlePanGesture:)];

    return _dynamicTransitionPanGesture;
}

2 个答案:

答案 0 :(得分:1)

您可能正在寻找以下内容:

self.slidingViewController.topViewAnchoredGesture = ECSlidingViewControllerAnchoredGestureTapping | ECSlidingViewControllerAnchoredGesturePanning;

在示例TransitionFun项目中的METransitionsViewController.m中。

它控制顶视图在锚定到侧面时对手势的行为方式。 您可以参考Anchored Top Views Gesture了解更多信息。

答案 1 :(得分:0)

正如@eric指出的那样,UIBar按钮只显示菜单。

如果您希望它关闭同一IBAction上的菜单,您需要添加更多逻辑:

- (IBAction)menuButtonTapped:(id)sender {
   //Chek the current position
   if([self.slidingViewController currentTopViewPosition]==2){
      //show menu
      [self.slidingViewController anchorTopViewToRightAnimated:YES];
   }else{
      //Dismiss menu
      [self.slidingViewController resetTopViewAnimated:YES];
   }
}