First, Introduction
The slide-by menu has become an extremely popular design for apps, whether it's transactional, efficiency, or life-like apps. The side-by-side menu is well known to developers for Path 2.0 and Facebook, and there are many popular apps in the country that use a sliding menu, such as QQ, NetEase email, and so on.
iOS doesn't have a component like a slider bar, so we need to write a slide-bar control ourselves, so I found a side-by-side menu control on GitHub that's easy to use and simple to start with, in order not to reinvent the wheel, address: https://github.com/ john-lluch/swrevealviewcontroller/tree/master/
Let's use the controls above to make a small demo of the slide bar to teach you the quick start of the slide-bar control.
The demo interface is shown below:
II. instructions for use the first step: import SWRevealViewController.h and SWREVEALVIEWCONTROLLER.M files The second step: writing the intermediate display interface Centerviewcontroller
By setting the Pangesturerecognizer method in Swrevealviewcontroller in the Viewdidload method, you can swipe on the main interface to appear on the left or right side of the menu. Set the Revealtoggle: Method can be achieved by clicking on the left menu and the middle interface switch. Set the Rightrevealtoggle: method to achieve the right menu and the middle interface switch. Here is the code for the middle interface:
//注册该页面可以执行滑动切换 SWRevealViewController *revealController = self.revealViewController; [self.view addGestureRecognizer:revealController.panGestureRecognizer]; // 注册该页面可以执行点击切换 [leftBtn addTarget:revealController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside]; [rightBtn addTarget:revealController action:@selector(rightRevealToggle:) forControlEvents:UIControlEventTouchUpInside];
The third step, write the left menu bar Leftviewcontroller
The left menu bar is made up of a uitableview that we execute [revealviewcontroller pushfrontviewcontroller:viewcontroller animated in each cell's click Method: YES]; Toggle the operation of the intermediate interface. The code is as follows:
- (void) TableView: (uitableview *) TableView Didselectrowatindexpath: ( Nsindexpath *) indexpath{swrevealviewcontroller *revealviewcontroller = self.revealviewcontroller; uiviewcontroller *viewcontroller; switch (Indexpath.row) {case Span class= "hljs-number" >0:viewcontroller = [[Centerview1controller alloc] init]; break; case 1:viewcontroller = [[Centerview2controller alloc] init]; Span class= "Hljs-keyword" >break; default: break;} [Revealviewcontroller pushfrontviewcontroller:viewcontroller animated:YES];}
Fourth step, write the right menu bar Rightviewcontroller
Here is the main demonstration left menu bar, here do not do too much description. Replace it with a simple viewcontroller.
Fifth step, in the APPDELEGATE.M file-(BOOL) application: (uiapplication) Application didfinishlaunchingwithoptions: (NsdictionaryThe Launchoptions method configures the above interface to set the left menu bar, the right menu bar, and the middle home page, respectively.
See Code comments:
- (BOOL) Application: (UIApplication *) Application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions {Self. window = [[UIWindow alloc] Initwithframe:[[uiscreen mainscreen] bounds]];Left menu bar Leftviewcontroller *leftviewcontroller = [[Leftviewcontroller alloc] init];Home Centerview1controller *centerview1controller = [[Centerview1controller alloc] init];Right menu bar Rightviewcontroller *rightviewcontroller = [[Rightviewcontroller alloc] init]; Swrevealviewcontroller *revealviewcontroller = [[Swrevealviewcontroller alloc] Initwithrearviewcontroller: Leftviewcontroller Frontviewcontroller:centerview1controller]; Revealviewcontroller. Rightviewcontroller = Rightviewcontroller;The width of the floating layer from the left margin Revealviewcontroller. rearviewrevealwidth = 230; //revealviewcontroller.rightviewrevealwidth = 230; //Whether to let the floating layer bounce back in situ //mainrevealcontroller.bouncebackonoverdraw = NO; [Revealviewcontroller setfrontviewposition:frontviewpositionleft animated:YES]; self. Window. Rootviewcontroller = Revealviewcontroller; self. Window. backgroundcolor = [uicolor whitecolor]; [Self. window makekeyandvisible]; return YES;}
Iii. Summary
The next step is to use this interface as the main frame to write a series of blogs about iOS animations and the use of pop animations on Facebook's open source animation project. Please look forward to it.
Four
Github:https://github.com/yixiangboy/iosanimationdemo
If you still have some use for you, give it to a star. Your support is my motivation to continue.
Blogger's words
I have seen a lot of other people's blogs before and learned a lot of things. Now I'm ready to write a blog, hoping to help some people.
My Contact information:
Weibo: Sina Weibo
Blog: http://blog.csdn.net/yixiangboy
Github:https://github.com/yixiangboy
iOS development UI chapter--A side-slip menu Slidingmenu