[Swift in Xcode]How to making slide out menu

2016-01-27

Slide out menu is very important element in IOS developing. There are many open source codes on websites. In this article, I am going to illustrate how to use SWRevealViewController to make slide out menu. There are four steps:

  • Download the package from gitHub
  • Import the file and do some settings
  • Making connections between viewController
  • Active the menu button
    Also, there is a brilliant video in youTube, and I learned from that, if you are interested in, you can check this link YouTube link

Download the package from gitHub

First, you need to download the packages from the gitHub, here is the link. gitHub link Actually, we do not need all the files, however, download everything should be useful. The two files what we need are inside SWRevealViewController/SWRevealViewController , called SWRevealViewController.h and SWRevealViewController.m Then, you can new your new Xcode project.

Import the file and do some settings

Drag that two files into the xCode project. It should come out with a alert message that asks “Would you like to configure an Objective-C bridging header“, just click yes. Then we will have a new file called yourProjectName-bridging header.h, add the following line into that file #import "SWRevealViewController.h"

Making connections between viewController

Drag a new view Controller in our main storyboard, and set it as the “SWRealViewController”, drag another tableView Controller, a navigation Controller, and a viewController(initial one), create navigation Connection between navigation controller and initial viewController. Control drag the SWRealViewController to the tableViewController, and set the Manual Segue to be reveal view controller set controller, also click that segue and update the storyBoard segue identifier to sw_rear(means left side bar). Also, the manual segue between realViewController and navigation Controller is reveal view controller set controller as well. 🙂 Cools, we have done most things. In the initial controller, we just need to create a navigation bar and add a bar item. Then, we need to active that button XDDD

Active the menu button

Control drag that item bar and create a connection in the ViewController file, let we suppose that the name of that bar item is “open”. Add the following code to inside the override func viewDidLoad()

1
2
open.target = self.revealViewController()
open.action = Selector("revealToggle:")

There is one more thing you need to pay attention is do not forget to set the initial view Controller!!

Cons! Now, build your app, I think it should works. If you still want to learn how to create a right side bar, the basic idea is to change the sw_rear to sw_right. And I strongly recommend that you should check that video, because it contains more useful application for swrevealviewcontroller, hopes you all enjoys this article. 🙂

There is the link for this project in youTube, many thanks to Jared Davidson, I really love the videos he put on youTube. project download


Comments: