CDRTranslucentSideBar is a useful sidebar menu library for iOS. You can craete beautiful blurred sidebar using CDRTranslucentSideBar.
pod 'CDRTranslucentSideBar'
iOS7.0 or higher.
Import CDRTranslucentSideBar.h
into ViewController and create property of sidebar.
#import "CDRTranslucentSideBar.h"
@interface CDRViewController () <CDRTranslucentSideBarDelegate>
@property (nonatomic, strong) CDRTranslucentSideBar *sideBar;
@property (nonatomic, strong) CDRTranslucentSideBar *rightSideBar;
@end
Initialize the sidebar and set properties in viewDidLoad.
self.sideBar = [[CDRTranslucentSideBar alloc] init];
self.sideBar.delegate = self;
self.sideBar.tag = 0;
//Example of Right Sidebar
self.rightSideBar = [[CDRTranslucentSideBar alloc] initWithDirectionFromRight:YES];
self.rightSideBar.delegate = self;
self.rightSideBar.translucentStyle = UIBarStyleBlack;
self.rightSideBar.tag = 1;
The sideBarWidth value. You can change the sidebar width by changing this value.
The animation duration value to show sidebar. This property specify the duration to show sidebar by action.
CDRTranslucentSideBar uses UIToolbar to provide blur effect. This property specifies its appearance.
Set content of sidebar by setContentViewInSideBar
.
You can use subclass of UIView for contentView, like UITableView.
//Example of Left Sidebar
UITableView *tableView = [[UITableView alloc] init];
tableView.dataSource = self;
tableView.delegate = self;
// Set ContentView in SideBar
[self.sideBar setContentViewInSideBar:tableView];
To show the sidebar using BarButtonItem, call show method.
- (IBAction)OnSideBarButtonTapped:(id)sender
{
[self.sideBar show];
}
CDRTranslucentSideBar can be shown by pan gesture.
Create UIPangestureRecognizer
and action to handle the gesture.
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panGestureRecognizer];
Create the action to handle the gesture.
- (void)handlePanGesture:(UIPanGestureRecognizer *)recognizer
{
// if you have left and right sidebar, you can control the pan gesture by start point.
if (recognizer.state == UIGestureRecognizerStateBegan) {
CGPoint startPoint = [recognizer locationInView:self.view];
// Left SideBar
if (startPoint.x < self.view.bounds.size.width / 2.0) {
self.sideBar.isCurrentPanGestureTarget = YES;
}
// Right SideBar
else {
self.rightSideBar.isCurrentPanGestureTarget = YES;
}
}
[self.sideBar handlePanGestureToShow:recognizer inView:self.view];
[self.rightSideBar handlePanGestureToShow:recognizer inView:self.view];
// if you have only one sidebar, do like following
// self.sideBar.isCurrentPanGestureTarget = YES;
//[self.sideBar handlePanGestureToShow:recognizer inView:self.view];
}
CDRTranslucentSideBar has four delegate methods.
- (void)sideBar:(CDRTranslucentSideBar *)sideBar didAppear:(BOOL)animated;
- (void)sideBar:(CDRTranslucentSideBar *)sideBar willAppear:(BOOL)animated;
- (void)sideBar:(CDRTranslucentSideBar *)sideBar didDisappear:(BOOL)animated;
- (void)sideBar:(CDRTranslucentSideBar *)sideBar willDisappear:(BOOL)animated;
See the sample project CDRTranslucentSideBar.xcodeproj
.
Please check this issue. don't show navigation bar item of main screen in slide menu like this plese give suggition
CDRTranslucentSideBar was originally created by Masamichi Ueta in the development of Chidori.
CDRTranslucentSideBar is used in Chidori, iOS application.
Ask nscallop on Twitter (@nscallop)
CDRTranslucentSideBar is available under the apache 2.0 license. See the LICENSE file for more info.