实现侧滑功能 CDRTranslucentSideBar<转>

CDRTranslucentSideBar

CDRTranslucentSideBar is a useful sidebar menu library for iOS. You can craete beautiful blurred sidebar using CDRTranslucentSideBar.

CDRTranslucentSideBar1   CDRTranslucentSideBar2

How To Get Started

Manual Installation

  • Download source code.
  • Add CDRTranslucentSideBar.h and CDRTranslucentSideBar.m from CDRTranslucentSideBar folder to your project.

Installation with CocoaPods

pod 'CDRTranslucentSideBar'

Requirements

iOS7.0 or higher.

Usage

Set up

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

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;
sideBarWidth

The sideBarWidth value. You can change the sidebar width by changing this value.

animationDuration

The animation duration value to show sidebar. This property specify the duration to show sidebar by action.

translucentStyle

CDRTranslucentSideBar uses UIToolbar to provide blur effect. This property specifies its appearance.

Set Content of Sidebar

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]; 

Show Sidebar

To show the sidebar using BarButtonItem, call show method.

- (IBAction)OnSideBarButtonTapped:(id)sender
{
    [self.sideBar show];
}

Set PanGestureRecognizer

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];
PanGesture Handler

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]; } 

Delegates

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;

Example

See the sample project CDRTranslucentSideBar.xcodeproj.

FAQ

How to add the side bar under navigation bar?

Please check this issue. don't show navigation bar item of main screen in slide menu like this plese give suggition

Credits

CDRTranslucentSideBar was originally created by Masamichi Ueta in the development of Chidori.

CDRTranslucentSideBar is used in Chidori, iOS application.

Contact

Ask nscallop on Twitter (@nscallop)

License

CDRTranslucentSideBar is available under the apache 2.0 license. See the LICENSE file for more info.

 

代码地址

https://github.com/chidori-app/CDRTranslucentSideBar

转载于:https://www.cnblogs.com/tion086/p/5113177.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值