【问题标题】:SWRevealViewController close left side view when navigation back button pressed按下导航返回按钮时,SWRevealViewController 关闭左侧视图
【发布时间】:2016-02-03 03:27:03
【问题描述】:

我有一个前视图控制器和一个滑动侧视图。在按下导航栏后退按钮时,我一直在将视图控制器弹出到前一个视图控制器。我希望我的侧视图滑出,如果我按下后退按钮时它是打开的。

我的代码是 我有一个带有后退按钮的导航栏:

 [navbar.backViewButton addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];

按下后退按钮:

-(void)backBtnClicked{
[self.navigationController popViewControllerAnimated:YES];
}

我知道我可以将revealtoggle添加为:

-(void)backBtnClicked{
[self.revealViewController revealToggleAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
}

但这给了我一个问题,如果之前关闭侧视图,它会切换并打开它,这是我在按下后退按钮时不想要的。

我想要类似的东西

-(void)backBtnClicked{
 if([self.revealViewController isSideViewAppeared or isSideviewShowing]){     
[self.revealViewController revealToggleAnimated:YES];
}
[self.navigationController popViewControllerAnimated:YES];
}

需要帮助..提前致谢

【问题讨论】:

  • 你能再添加一些代码吗
  • 如果它在根控制器下是一个SWL,你需要使用,[self.revealViewControllerrevealToggleAnimated:YES];,如果你的viecontroller在导航堆栈使用[self.navigationController popViewControllerAnimated:YES] ;
  • 我通过查看 swrevealview 委托方法找到了解决方案 :) 感谢您的帮助

标签: ios objective-c swrevealviewcontroller


【解决方案1】:

创建一个 bool 属性来存储它是打开还是关闭。在 viewWillAppear 中根据所述属性打开或关闭它。

【讨论】:

    【解决方案2】:

    我找到了答案,我只是想将侧视图显示为:

    [self.revealViewController revealToggleAnimated:YES];
    

    打开和关闭左视图..简单的解决方案是

    -(void)backBtnClicked{
    
    
    [self.revealViewController rightRevealToggleAnimated:YES];
    [self.navigationController popViewControllerAnimated:YES];
    }
    

    【讨论】:

      【解决方案3】:

      你必须使用SWRevealViewController导航方法进行弹出和推送。

      将此代码写入您的后退按钮操作方法。

        UINavigationController *frontNavigationController = (id)revealController.frontViewController;
              if ([frontNavigationController.topViewController isKindOfClass:[YourViewController class]] )        
                viewwaboutus=[[FlashViewController alloc]init];
      
                  UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewwaboutus];
                  [revealController pushFrontViewController:navigationController animated:YES];
              }
      

      也许对你有帮助。

      【讨论】:

        【解决方案4】:

        要在使用 SWRevealViewController 时手动关闭 Slide-Menu,让我们尝试一下:self.revealViewController().revealToggle(animated: true)

        【讨论】:

          【解决方案5】:

          在按钮操作中使用此代码。

          if (self.revealViewController.frontViewPosition == 4){
          
                      [self.revealViewController revealToggleAnimated:YES];
          }
          

          【讨论】:

            猜你喜欢
            • 2011-03-19
            • 1970-01-01
            • 2013-02-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多