测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | Apache 2 |
发布最新版本 | 2015年4月 |
由 maasaamiichii 维护。
CDRTranslucentSideBar 是一个实用的 iOS 侧边栏菜单库。您可以使用 CDRTranslucentSideBar 创建美丽的模糊侧边栏。
iOS 7.0 或更高版本。
将 CDRTranslucentSideBar.h
导入 ViewController 并创建侧边栏的属性。
#import "CDRTranslucentSideBar.h"
@interface CDRViewController () <CDRTranslucentSideBarDelegate>
@property (nonatomic, strong) CDRTranslucentSideBar *sideBar;
@property (nonatomic, strong) CDRTranslucentSideBar *rightSideBar;
@end
在 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;
侧边栏宽度的值。您可以通过更改此值来更改侧边栏宽度。
显示侧边栏的动画持续时间的值。此属性指定通过动作显示侧边栏的持续时间。
CDRTranslucentSideBar 使用 UIToolbar 提供模糊效果。此属性指定其外观。
通过 setContentViewInSideBar
设置侧边栏内容。您可以使用 UIView 的子类作为 contentView,如 UITableViewDataSource。
//Example of Left Sidebar
UITableView *tableView = [[UITableView alloc] init];
tableView.dataSource = self;
tableView.delegate = self;
// Set ContentView in SideBar
[self.sideBar setContentViewInSideBar:tableView];
要使用 BarButtonItem 显示侧边栏,请调用 show 方法。
- (IBAction)OnSideBarButtonTapped:(id)sender
{
[self.sideBar show];
}
CDRTranslucentSideBar 可以通过滑动手势显示。创建 UIPangestureRecognizer
和处理手势的动作。
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panGestureRecognizer];
创建处理手势的动作。
- (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有四个委托方法。
- (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;
请参考示例项目CDRTranslucentSideBar.xcodeproj
。
请检查这个问题。[不显示主屏幕的导航栏项在滑动菜单中,请提供建议](https://github.com/chidori-app/CDRTranslucentSideBar/issues/5)
CDRTranslucentSideBar最初由Masamichi Ueta在开发Chidori时创建。
CDRTranslucentSideBar用于Chidori,iOS应用程序。
在Twitter上询问nscallop(@nscallop)
CDRTranslucentSideBar遵循Apache 2.0许可协议。更多信息请参阅LICENSE文件。