简体   繁体   English

使用Swift中的SWRevealViewController手动segue

[英]Manual segue with SWRevealViewController in Swift

There is a great blog post over at http://www.appcoda.com/tag/swrevealviewcontroller/ that goes in to setting up SWRevealViewController which is a great component for slide out side menus ( https://github.com/John-Lluch/SWRevealViewController ) http://www.appcoda.com/tag/swrevealviewcontroller/上有一篇很棒的博客文章,其中介绍了设置SWRevealViewController,它是滑出侧边菜单的一个很好的组件( https://github.com/John- Lluch / SWRevealViewController

Unfortunately, there are no swift examples of how to perform a manual segue. 不幸的是,没有关于如何执行手动segue的快速示例。

Took a cleaner approach to storyboard support. 对故事板支持采取更清晰的方法。 SWRevealViewControllerSegue is now deprecated and you should use SWRevealViewControllerSegueSetController and SWRevealViewControllerSeguePushController instead. 现在不推荐使用SWRevealViewControllerSegue,您应该使用SWRevealViewControllerSegueSetController和SWRevealViewControllerSeguePushController。

I've tried something along the lines of: 我尝试过以下方面:

let navigationController = self.window?.rootViewController as! SWRevealViewController;

let viewController = navigationController.storyboard?.instantiateViewControllerWithIdentifier("ImportFileSelect") as! ImportFileSelect

navigationController.showViewController(viewController, sender: self)

This doesn't work though. 但这不起作用。 Any ideas? 有任何想法吗? I've trawled the web for swift examples, my next step is to learn objective c! 我已经在网上搜索了一些快速的例子,我的下一步是学习目标c!

In order to work you'll need to following steps: 为了工作,您需要执行以下步骤:

  • You need to instantiate the SWRevealViewController and then attach it to the root controller. 您需要实例化SWRevealViewController,然后将其附加到根控制器。
  • Then instantiate the destination controller. 然后实例化目标控制器。
  • Then create a navigation controller and set the destination controller as the rootViewController 然后创建一个导航控制器并将目标控制器设置为rootViewController
  • Finally push the navigation controller with SWReveal 最后用SWReveal推送导航控制器

     let storyboard = UIStoryboard(name: "Main", bundle: nil) let sw = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! SWRevealViewController self.view.window?.rootViewController = sw let destinationController = self.storyboard?.instantiateViewControllerWithIdentifier("StoryboardID") as! NameOfViewController let navigationController = UINavigationController(rootViewController: destinationController) sw.pushFrontViewController(navigationController, animated: true) 

I've kind of made some progress. 我有点进步了。 I can load in a new view controller, but it doesn't animate in anyway. 我可以加载一个新的视图控制器,但无论如何它都没有动画。 The code to do this, on a button click is: 单击按钮时执行此操作的代码为:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("TARGET_VIEW_CONTROLLER") as! UIViewController
var rvc:SWRevealViewController = self.revealViewController() as SWRevealViewController
rvc.pushFrontViewController(vc, animated: true)
  1. Download SWRevealViewController project's zip form Github . 下载SWRevealViewController项目的zip格式Github
  2. Drag SWRevealViewController.m and SWRevealViewController.h files from zip (SWRevealViewController folder) to your project, and Click “Yes” to the prompted message "Would you like to configure an Objective-C bridging header?" 将ZIP(SWRevealViewController文件夹)中的SWRevealViewController.m和SWRevealViewController.h文件拖到项目中,然后单击“是”以显示提示消息“是否要配置Objective-C桥接头?”
  3. Take a look at storyboard in RevealControllerStoryboardExample2 project. 看一下RevealControllerStoryboardExample2项目中的storyboard Design your storyboard with this example. 使用此示例设计故事板。

This is not how it should be done, but at least i found a way to do it. 这不是应该怎么做,但至少我找到了一种方法来做到这一点。

In the TableViewController where u have the slideOut menu do something like: 在TableViewController中你有slideOut菜单做类似的事情:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if(indexPath.row == <some position> ){
            let vc: AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("YOUR_DESTINATION_IDENTIFIER")
            self.showViewController(vc as! SWRevealViewController, sender: vc)
        }

The one that satisfy the condition will segue with default animation, not like the slide out menu normally does. 满足条件的那个将使用默认动画进行segue,而不像幻灯片菜单通常那样。

After, in storyboard, do a normal Reveal View Controller Push controller, and as long as it doesn't satisfy the condition it will exit the slide out menu normally 在故事板中,执行一个普通的Reveal View Controller Push控制器,只要它不满足条件,它就会正常退出滑出菜单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM