如何返回当前的View Controller? [英] How to go back to current View Controller?

查看:70
本文介绍了如何返回当前的View Controller?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中实现ECSlidingViewController.一切正常,当我按下菜单按钮(UIBar)时,左侧菜单就会滑动.但是再次按菜单按钮不会恢复当前的ViewController.

I am implementing ECSlidingViewController in my app. Everything works fine, when I hit the menu button (UIBar) the left menu slides. But pressing the menu button again does not bring back the current ViewController.

它在示例应用程序中有效,但是我找不到找到带回当前控制器的那一行代码.

It works in the sample app, but I cannot find that line of code that brings back the current controller.

以下是显示菜单的代码:

Here is the code to show the menu:

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

现在,到处都在寻找可以消除左菜单布局但找不到的那部分代码.在某处一定是埋葬...

Now I am looked everywhere for the part of the code that can dismiss the left menu layout but could not find it. It must be burry somewhere...

Github项目

如何通过按菜单UIBar按钮返回到当前的View Controller?

How do you get back to the current View Controller by pressing the Menu UIBar button ?

@Eric 让我大开眼界正在执行该事件.似乎UIPanGestureRecognizer是负责重新显示主屏幕的人,很遗憾,在实现该代理之后,我无法使它正常工作.

@Eric opened my eyes on what is performing that event. It seems like the UIPanGestureRecognizer is the one responsible to redisplay the main screen, unfortunately I couldnt get it to work after implementing that deleguate.

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

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

    return _dynamicTransitionPanGesture;
}

推荐答案

正如@eric所指出的,UIBar按钮仅显示菜单.

As @eric pointed out, the UIBar button only displays the menu.

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

If you want it to dismiss the menu on the same IBAction you will need to add more logic:

- (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];
   }
}

这篇关于如何返回当前的View Controller?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆