ViewController.h
#import <UIKit/UIKit.h>
#import “FlyOverSideMenuView.h”
#import “FirstViewController.h”
#import “SecondViewController.h”
@interface ViewController : UIViewController<BTSimpleSideMenuDelegate>
@property(nonatomic)FlyOverSideMenuView *sideMenu;
– (IBAction)buttonActionShowSliderMain:(id)sender;
– (IBAction)buttonActionBackMain:(id)sender;
@end
ViewController.m
#import “ViewController.h”
@interface ViewController ()
@end
@implementation ViewController
– (void)viewDidLoad {
[super viewDidLoad];
// sideMenu = [[BTSimpleSideMenu alloc]initWithItemTitles:@[@”One”, @”Two”, @”Three”, @”Four”,@”Five”, @”Six”, @”Seven”]
// andItemImages:@[
// [UIImage imageNamed:@”icon1.jpeg”],
// [UIImage imageNamed:@”icon2.jpeg”],
// [UIImage imageNamed:@”icon3.jpeg”],
// [UIImage imageNamed:@”icon4.jpeg”],
// [UIImage imageNamed:@”icon5.jpeg”]
// ]
// addToViewController:self];
FlyOverSideMenuItem *item1 = [[FlyOverSideMenuItem alloc]initWithTitle:@”One”
image:[UIImage imageNamed:@”icon1.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 1″);
}];
FlyOverSideMenuItem *item2 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Two”
image:[UIImage imageNamed:@”icon2.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 2″);
}];
FlyOverSideMenuItem *item3 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Three”
image:[UIImage imageNamed:@”icon3.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 3″);
}];
FlyOverSideMenuItem *item4 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Four”
image:[UIImage imageNamed:@”icon4.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 4″);
}];
FlyOverSideMenuItem *item5 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Five”
image:[UIImage imageNamed:@”icon5.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 5″);
}];
_sideMenu = [[FlyOverSideMenuView alloc]initWithItem:@[item1, item2, item3, item4, item5] addToViewController:self];
_sideMenu.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
}
– (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
– (IBAction)buttonActionShowSliderMain:(id)sender
{
[_sideMenu toggleMenu];
}
– (IBAction)buttonActionBackMain:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma -mark BTSimpleSideMenuDelegate
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu didSelectItemAtIndex:(NSInteger)index
{
NSLog(@”Item Cliecked : %ld”, (long)index);
if (index == 0)
{
// ViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”ViewController”];
// [self.navigationController pushViewController:viewControllerObject animated:YES];
}
else if (index == 1)
{
FirstViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”FirstViewController”];
[self.navigationController pushViewController:viewControllerObject animated:YES];
}
else if (index == 2)
{
SecondViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”SecondViewController”];
[self.navigationController pushViewController:viewControllerObject animated:YES];
}
}
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu selectedItemTitle:(NSString *)title
{
NSLog(@”Item Cliecked : %@”, title);
}
@end
FirstViewController.h
#import <UIKit/UIKit.h>
#import “FlyOverSideMenuView.h”
#import “ViewController.h”
#import “SecondViewController.h”
@interface FirstViewController : UIViewController<BTSimpleSideMenuDelegate>
@property(nonatomic)FlyOverSideMenuView *sideMenu;
– (IBAction)buttonActionShowSliderFirst:(id)sender;
– (IBAction)buttonActionBackFirst:(id)sender;
@end
FirstViewController.m
#import “FirstViewController.h”
@interface FirstViewController ()
@end
@implementation FirstViewController
– (void)viewDidLoad {
[super viewDidLoad];
// sideMenu = [[BTSimpleSideMenu alloc]initWithItemTitles:@[@”One”, @”Two”, @”Three”, @”Four”,@”Five”, @”Six”, @”Seven”]
// andItemImages:@[
// [UIImage imageNamed:@”icon1.jpeg”],
// [UIImage imageNamed:@”icon2.jpeg”],
// [UIImage imageNamed:@”icon3.jpeg”],
// [UIImage imageNamed:@”icon4.jpeg”],
// [UIImage imageNamed:@”icon5.jpeg”]
// ]
// addToViewController:self];
FlyOverSideMenuItem *item1 = [[FlyOverSideMenuItem alloc]initWithTitle:@”One”
image:[UIImage imageNamed:@”icon1.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 1″);
}];
FlyOverSideMenuItem *item2 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Two”
image:[UIImage imageNamed:@”icon2.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 2″);
}];
FlyOverSideMenuItem *item3 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Three”
image:[UIImage imageNamed:@”icon3.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 3″);
}];
FlyOverSideMenuItem *item4 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Four”
image:[UIImage imageNamed:@”icon4.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 4″);
}];
FlyOverSideMenuItem *item5 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Five”
image:[UIImage imageNamed:@”icon5.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 5″);
}];
_sideMenu = [[FlyOverSideMenuView alloc]initWithItem:@[item1, item2, item3, item4, item5] addToViewController:self];
_sideMenu.delegate = self;
// Do any additional setup after loading the view.
}
– (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark – Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
– (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
– (IBAction)buttonActionShowSliderFirst:(id)sender {
[_sideMenu toggleMenu];
}
– (IBAction)buttonActionBackFirst:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma -mark BTSimpleSideMenuDelegate
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu didSelectItemAtIndex:(NSInteger)index
{
NSLog(@”Item Cliecked : %ld”, (long)index);
if (index == 0)
{
ViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”ViewController”];
[self.navigationController pushViewController:viewControllerObject animated:YES];
}
else if (index == 1)
{
// FirstViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”FirstViewController”];
// [self.navigationController pushViewController:viewControllerObject animated:YES];
}
else if (index == 2)
{
SecondViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”SecondViewController”];
[self.navigationController pushViewController:viewControllerObject animated:YES];
}
}
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu selectedItemTitle:(NSString *)title
{
NSLog(@”Item Cliecked : %@”, title);
}
@end
SecondViewController.h
#import <UIKit/UIKit.h>
#import “FlyOverSideMenuView.h”
#import “ViewController.h”
#import “FirstViewController.h”
@interface SecondViewController : UIViewController<BTSimpleSideMenuDelegate>
@property(nonatomic)FlyOverSideMenuView *sideMenu;
– (IBAction)buttonActionShowSliderSecond:(id)sender;
– (IBAction)buttonActionBackSecond:(id)sender;
@end
SecondViewController.m
#import “SecondViewController.h”
@interface SecondViewController ()
@end
@implementation SecondViewController
– (void)viewDidLoad {
[super viewDidLoad];
// sideMenu = [[BTSimpleSideMenu alloc]initWithItemTitles:@[@”One”, @”Two”, @”Three”, @”Four”,@”Five”, @”Six”, @”Seven”]
// andItemImages:@[
// [UIImage imageNamed:@”icon1.jpeg”],
// [UIImage imageNamed:@”icon2.jpeg”],
// [UIImage imageNamed:@”icon3.jpeg”],
// [UIImage imageNamed:@”icon4.jpeg”],
// [UIImage imageNamed:@”icon5.jpeg”]
// ]
// addToViewController:self];
FlyOverSideMenuItem *item1 = [[FlyOverSideMenuItem alloc]initWithTitle:@”One”
image:[UIImage imageNamed:@”icon1.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 1″);
}];
FlyOverSideMenuItem *item2 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Two”
image:[UIImage imageNamed:@”icon2.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 2″);
}];
FlyOverSideMenuItem *item3 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Three”
image:[UIImage imageNamed:@”icon3.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 3″);
}];
FlyOverSideMenuItem *item4 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Four”
image:[UIImage imageNamed:@”icon4.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 4″);
}];
FlyOverSideMenuItem *item5 = [[FlyOverSideMenuItem alloc]initWithTitle:@”Five”
image:[UIImage imageNamed:@”icon5.png”]
onCompletion:^(BOOL success, FlyOverSideMenuItem *item) {
NSLog(@”I am Item 5″);
}];
_sideMenu = [[FlyOverSideMenuView alloc]initWithItem:@[item1, item2, item3, item4, item5] addToViewController:self];
_sideMenu.delegate = self;
// Do any additional setup after loading the view.
}
– (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark – Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
– (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
– (IBAction)buttonActionShowSliderSecond:(id)sender {
[_sideMenu toggleMenu];
}
– (IBAction)buttonActionBackSecond:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma -mark BTSimpleSideMenuDelegate
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu didSelectItemAtIndex:(NSInteger)index
{
NSLog(@”Item Cliecked : %ld”, (long)index);
if (index == 0)
{
ViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”ViewController”];
[self.navigationController pushViewController:viewControllerObject animated:YES];
}
else if (index == 1)
{
FirstViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”FirstViewController”];
[self.navigationController pushViewController:viewControllerObject animated:YES];
}
else if (index == 2)
{
// SecondViewController *viewControllerObject = [[UIStoryboard storyboardWithName:@”Main” bundle:nil] instantiateViewControllerWithIdentifier:@”SecondViewController”];
// [self.navigationController pushViewController:viewControllerObject animated:YES];
}
}
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu selectedItemTitle:(NSString *)title
{
NSLog(@”Item Cliecked : %@”, title);
}
@end
FlyOverSideMenuView.h
#import <Foundation/Foundation.h>
#import “FlyOverSideMenuItem.h”
#import “Constant.h”
#define MAIN_VIEW_TAG 1
#define TITLE_LABLE_TAG 2
#define IMAGE_VIEW_TAG 3
@class FlyOverSideMenuView;
@protocol BTSimpleSideMenuDelegate <NSObject>
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu didSelectItemAtIndex:(NSInteger)index;
-(void)BTSimpleSideMenu:(FlyOverSideMenuView *)menu selectedItemTitle:(NSString *)title;
@end
@interface FlyOverSideMenuView : UIView<UITableViewDelegate, UITableViewDataSource>
{
@private
UITableView *menuTable;
NSArray *titleArray;
NSArray *imageArray;
NSArray *itemsArray;
BOOL isOpen;
UITapGestureRecognizer *gesture;
UISwipeGestureRecognizer *leftSwipe, *rightSwipe;
}
@property (nonatomic, retain) FlyOverSideMenuItem *selectedItem;
@property(nonatomic, weak) id <BTSimpleSideMenuDelegate> delegate;
-(instancetype) initWithItem:(NSArray *)items addToViewController:(id)sender;
//-(instancetype) initWithItemTitles:(NSArray *)itemsTitle addToViewController:(id)sender;
//-(instancetype) initWithItemTitles:(NSArray *)itemsTitle andItemImages:(NSArray *)itemsImage addToViewController:(UIViewController *)sender;
-(void)show;
-(void)hide;
-(void)toggleMenu;
@end
FlyOverSideMenuView.m
#import “FlyOverSideMenuView.h”
@implementation FlyOverSideMenuView
-(instancetype) initWithItem:(NSArray *)items addToViewController:(id)sender {
if ((self = [super init])) {
// perform the other initialization of items.
[self commonInit:sender];
itemsArray = items;
}
return self;
}
-(instancetype)initWithItemTitles:(NSArray *)itemsTitle addToViewController:(UIViewController *)sender {
if ((self = [super init])) {
// perform the other initialization of items.
[self commonInit:sender];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
for(int i = 0;i<[itemsTitle count]; i++){
FlyOverSideMenuItem *temp = [[FlyOverSideMenuItem alloc]initWithTitle:[itemsTitle objectAtIndex:i]
image:nil onCompletion:nil];
[tempArray addObject:temp];
}
itemsArray = tempArray;
}
return self;
}
-(instancetype)initWithItemTitles:(NSArray *)itemsTitle andItemImages:(NSArray *)itemsImage addToViewController:(UIViewController *)sender{
if ((self = [super init])) {
// perform the other initialization of items.
[self commonInit:sender];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
for(int i = 0;i<[itemsTitle count]; i++){
FlyOverSideMenuItem *temp = [[FlyOverSideMenuItem alloc]initWithTitle:[itemsTitle objectAtIndex:i]
image:[itemsImage objectAtIndex:i]
onCompletion:nil];
[tempArray addObject:temp];
}
itemsArray = tempArray;
}
return self;
}
-(void)commonInit:(UIViewController *)sender
{
self.frame = CGRectMake(WD, 0, WD, HT);
self.backgroundColor = [UIColor clearColor];
if(!sender.navigationController.navigationBarHidden)
{
menuTable = [[UITableView alloc]initWithFrame:CGRectMake(WD/4.32, 15, WD/1.3, HT) style:UITableViewStyleGrouped];
}
else
{
menuTable = [[UITableView alloc]initWithFrame:CGRectMake(WD/4.32, –15, WD/1.3, HT) style:UITableViewStyleGrouped];
}
[menuTable setBackgroundColor:[UIColor clearColor]];
[menuTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
menuTable.scrollEnabled = NO;
menuTable.delegate = self;
menuTable.dataSource = self;
menuTable.alpha = 0;
isOpen = NO;
[self addSubview:menuTable];
gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toggleMenu)];
gesture.numberOfTapsRequired = 2;
leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(show)];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
rightSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[sender.view addSubview:self];
[sender.view addGestureRecognizer:gesture];
[sender.view addGestureRecognizer:rightSwipe];
[sender.view addGestureRecognizer:leftSwipe];
}
-(void)toggleMenu{
if(!isOpen){
[self show];
}else {
[self hide];
}
}
-(void)show{
if(!isOpen){
[UIView animateWithDuration:0.5 animations:^{
self.frame = CGRectMake(0, 0, WD, HT);
menuTable.frame = CGRectMake(menuTable.frame.origin.x, menuTable.frame.origin.y+15, WD/1.3, HT);
menuTable.alpha = 1;
} completion:^(BOOL finished) {
}];
isOpen = YES;
}
}
-(void)hide {
if(isOpen){
[UIView animateWithDuration:0.5 animations:^{
self.frame = CGRectMake(WD, 0, WD, HT);
menuTable.frame = CGRectMake(menuTable.frame.origin.x, menuTable.frame.origin.y–15, WD/1.3, HT);
menuTable.alpha = 0;
}];
isOpen = NO;
}
}
#pragma -mark tableView Delegates
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [itemsArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UILabel *titleLabel;
UIImageView *imageView;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”cell”];
FlyOverSideMenuItem *item = [itemsArray objectAtIndex:indexPath.row];
if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@”cell”];
cell.backgroundColor = [UIColor whiteColor];
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(WD/16, HT/56.8, WD/16, HT/28.4)];
imageView.tag = IMAGE_VIEW_TAG;
[cell.contentView addSubview:imageView];
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(WD/4.5, HT/47.3, WD/1.70, HT/37.8)];
titleLabel.tag = TITLE_LABLE_TAG;
titleLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1];
titleLabel.minimumFontSize = 9;
[cell.contentView addSubview:titleLabel];
}
else
{
titleLabel = (UILabel *)[cell.contentView viewWithTag:TITLE_LABLE_TAG];
imageView = (UIImageView *)[cell.contentView viewWithTag:IMAGE_VIEW_TAG];
}
titleLabel.text = item.title;
imageView.image = item.imageView.image;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return HT/14.2;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.delegate && [self.delegate respondsToSelector:@selector(BTSimpleSideMenu:didSelectItemAtIndex:)])
{
[self.delegate BTSimpleSideMenu:self didSelectItemAtIndex:indexPath.row];
}
if (self.delegate && [self.delegate respondsToSelector:@selector(BTSimpleSideMenu:selectedItemTitle:)])
{
[self.delegate BTSimpleSideMenu:self selectedItemTitle:[[itemsArray objectAtIndex:indexPath.row] title]];
}
_selectedItem = [itemsArray objectAtIndex:indexPath.row];
[self hide];
if (_selectedItem.block) {
BOOL success= YES;
_selectedItem.block(success, _selectedItem);
}
[menuTable deselectRowAtIndexPath:indexPath animated:YES];
}
@end
FlyOverSideMenuItem.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class FlyOverSideMenuItem;
typedef void (^completion)(BOOL success, FlyOverSideMenuItem *item);
@interface FlyOverSideMenuItem : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, copy) completion block;
-(id)initWithTitle:(NSString *)title image:(UIImage *)image onCompletion:(completion)completionBlock;
@end
FlyOverSideMenuItem.m
#import “FlyOverSideMenuItem.h”
@implementation FlyOverSideMenuItem
-(id)initWithTitle:(NSString *)title image:(UIImage *)image onCompletion:(completion)completionBlock;
{
self = [super init];
if(self)
{
self.title = title;
self.image = image;
self.block = completionBlock;
self.imageView = [[UIImageView alloc]initWithImage:image];
self.imageView.frame = CGRectMake(0, 0, 40, 40);
}
return self;
}
@end