A list,
The sideslip menu has become a very common design in apps, whether transaction, efficiency or life apps. As Path 2.0 and Facebook are well known to developers, the side swipe menu is also used in many popular apps in China, such as QQ, NetEase Email, Zhihu and so on. IOS officially does not provide components similar to the slider bar, so we need to write a slider bar control, in order not to duplicate the wheel, I found a simple and convenient to use on Github, easy for beginners to start the slider menu control, Demo download address: this is my IOS communication group: 624212887, group file download, no matter you are small white or big ox warmly welcome into the group, share interview experience, discuss technology, we exchange learning and growth together! Hope to help developers avoid detours.
Below we are using the above control, to do a small Demo of the slider bar, to teach you a quick introduction to the slider bar control. The Demo interface is shown as follows:
2. Instructions for use
Step 1: Import the SwRevealViewController.h and SwRevealViewController.m files
Step 2: Write CenterViewController, the intermediate display interface
Set the panGestureRecognizer method in the SWRevealViewController in the viewDidLoad method to slide on the main screen to show the left or right menu. Set revealToggle: The method allows you to switch between the left menu and the middle screen with one click. Set the right menu to ggle: This method toggles the right menu and the middle screen. Here is the code for the intermediate interface:
// Register the page to perform a sliding switch
SWRevealViewController *revealController = self.revealViewController;
[self.view addGestureRecognizer:revealController.panGestureRecognizer];
// Register the page to perform click-to-switch
[leftBtn addTarget:revealController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
[rightBtn addTarget:revealController action:@selector(rightRevealToggle:) forControlEvents:UIControlEventTouchUpInside];
Copy the code
Step 3: Write the left menu bar LeftViewController
On the left side of the menu bar is composed of a UITableView, we performed in each cell of the click method [revealViewController pushFrontViewController: viewController animated: YES]; Switch the middle screen. The code is as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SWRevealViewController *revealViewController = self.revealViewController;
UIViewController *viewController;
switch (indexPath.row) {
case 0:
viewController = [[CenterView1Controller alloc] init];
break;
case 1:
viewController = [[CenterView2Controller alloc] init];
break;
default:
break;
}
[revealViewController pushFrontViewController:viewController animated:YES];
}
Copy the code
Step 4, write the right menu bar RightViewController
The left-hand menu bar is mainly demonstrated here, so I won’t go into too much detail here. I’m going to replace it with a simple ViewController.
In the fifth step, the AppDelegate. M file – (BOOL) application: (UIApplication) application didFinishLaunchingWithOptions: (NSDictionary You can set the menu bar on the left, menu bar on the right, and home page in the middle.
See the code comment:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Left menu bar
LeftViewController *leftViewController = [[LeftViewController alloc] init];
/ / home page
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 spring back to its original position
//mainRevealController.bounceBackOnOverdraw = NO;
[revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
self.window.rootViewController = revealViewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Copy the code
Third, summary
Next, I’m going to use this interface as the main framework to write a series of blog posts about iOS animation summaries and the use of Pop Animation, Facebook’s open source animation project. Stay tuned.
4. Download address
Demo download address: this is a my iOS communication group: 624212887, group file download, no matter you are small white or big ox warmly welcome to enter the group, share interview experience, discuss technology, we exchange learning to grow together! Hope to help developers avoid detours.
If you think you still have some use, pay attention to xiaobian + like this article. Your support is my motivation to continue.
Next post: Summary of iOS animation
Article from the network, if there is infringement, please contact xiaobian to delete.