Skip to content

Commit

Permalink
- show how menu table view can be styled in demo app
Browse files Browse the repository at this point in the history
- fold menu table view automatically when an item is selected
- added a delegate method to ask if menu table view should be collapsed when an item is selected
- added a method to fold/unfold menu table view with/without animation
- removed redundant view controllers in demo
  • Loading branch information
honcheng committed Oct 27, 2012
1 parent e3afdb8 commit f14c253
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 174 deletions.
32 changes: 14 additions & 18 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
F893850B163AD49E0085C3BB /* ShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = F89384FD163AD49E0085C3BB /* ShadowView.m */; }; F893850B163AD49E0085C3BB /* ShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = F89384FD163AD49E0085C3BB /* ShadowView.m */; };
F893850C163AD49E0085C3BB /* TouchThroughUIView.m in Sources */ = {isa = PBXBuildFile; fileRef = F89384FF163AD49E0085C3BB /* TouchThroughUIView.m */; }; F893850C163AD49E0085C3BB /* TouchThroughUIView.m in Sources */ = {isa = PBXBuildFile; fileRef = F89384FF163AD49E0085C3BB /* TouchThroughUIView.m */; };
F893850D163AD49E0085C3BB /* UIView+Screenshot.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938501163AD49E0085C3BB /* UIView+Screenshot.m */; }; F893850D163AD49E0085C3BB /* UIView+Screenshot.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938501163AD49E0085C3BB /* UIView+Screenshot.m */; };
F8938513163AD5CE0085C3BB /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938512163AD5CE0085C3BB /* FirstViewController.m */; };
F8938516163AD5D70085C3BB /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938515163AD5D70085C3BB /* SecondViewController.m */; };
F8938519163AD5E20085C3BB /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938518163AD5E10085C3BB /* ThirdViewController.m */; };
F8938535163AD6FA0085C3BB /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8938534163AD6FA0085C3BB /* QuartzCore.framework */; }; F8938535163AD6FA0085C3BB /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8938534163AD6FA0085C3BB /* QuartzCore.framework */; };
F893853C163AD8680085C3BB /* DemoMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = F893853B163AD8680085C3BB /* DemoMenuController.m */; }; F893853C163AD8680085C3BB /* DemoMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = F893853B163AD8680085C3BB /* DemoMenuController.m */; };
F8C000CF163B67DF00654C1E /* cellBg@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F8C000CE163B67DF00654C1E /* cellBg@2x.png */; };
F8C000D3163B691E00654C1E /* cellBgSelected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F8C000D2163B691E00654C1E /* cellBgSelected@2x.png */; };
F8C000D6163B6B7300654C1E /* DemoRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8C000D5163B6B7300654C1E /* DemoRootViewController.m */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */


/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
Expand Down Expand Up @@ -73,16 +73,14 @@
F89384FF163AD49E0085C3BB /* TouchThroughUIView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TouchThroughUIView.m; sourceTree = "<group>"; }; F89384FF163AD49E0085C3BB /* TouchThroughUIView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TouchThroughUIView.m; sourceTree = "<group>"; };
F8938500163AD49E0085C3BB /* UIView+Screenshot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Screenshot.h"; sourceTree = "<group>"; }; F8938500163AD49E0085C3BB /* UIView+Screenshot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Screenshot.h"; sourceTree = "<group>"; };
F8938501163AD49E0085C3BB /* UIView+Screenshot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Screenshot.m"; sourceTree = "<group>"; }; F8938501163AD49E0085C3BB /* UIView+Screenshot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Screenshot.m"; sourceTree = "<group>"; };
F8938511163AD5CE0085C3BB /* FirstViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = "<group>"; };
F8938512163AD5CE0085C3BB /* FirstViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = "<group>"; };
F8938514163AD5D70085C3BB /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = "<group>"; };
F8938515163AD5D70085C3BB /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = "<group>"; };
F8938517163AD5E10085C3BB /* ThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewController.h; sourceTree = "<group>"; };
F8938518163AD5E10085C3BB /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = "<group>"; };
F8938534163AD6FA0085C3BB /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; F8938534163AD6FA0085C3BB /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
F893853A163AD8680085C3BB /* DemoMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoMenuController.h; sourceTree = "<group>"; }; F893853A163AD8680085C3BB /* DemoMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoMenuController.h; sourceTree = "<group>"; };
F893853B163AD8680085C3BB /* DemoMenuController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoMenuController.m; sourceTree = "<group>"; }; F893853B163AD8680085C3BB /* DemoMenuController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoMenuController.m; sourceTree = "<group>"; };
F8938557163ADFE40085C3BB /* PaperFoldMenuControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PaperFoldMenuControllerDelegate.h; path = ../PaperFoldMenuController/PaperFoldMenuControllerDelegate.h; sourceTree = "<group>"; }; F8938557163ADFE40085C3BB /* PaperFoldMenuControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PaperFoldMenuControllerDelegate.h; path = ../PaperFoldMenuController/PaperFoldMenuControllerDelegate.h; sourceTree = "<group>"; };
F8C000CE163B67DF00654C1E /* cellBg@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "cellBg@2x.png"; sourceTree = "<group>"; };
F8C000D2163B691E00654C1E /* cellBgSelected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "cellBgSelected@2x.png"; sourceTree = "<group>"; };
F8C000D4163B6B7300654C1E /* DemoRootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoRootViewController.h; sourceTree = "<group>"; };
F8C000D5163B6B7300654C1E /* DemoRootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoRootViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */


/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -136,12 +134,8 @@
F8938467163AD2BE0085C3BB /* AppDelegate.m */, F8938467163AD2BE0085C3BB /* AppDelegate.m */,
F893853A163AD8680085C3BB /* DemoMenuController.h */, F893853A163AD8680085C3BB /* DemoMenuController.h */,
F893853B163AD8680085C3BB /* DemoMenuController.m */, F893853B163AD8680085C3BB /* DemoMenuController.m */,
F8938511163AD5CE0085C3BB /* FirstViewController.h */, F8C000D4163B6B7300654C1E /* DemoRootViewController.h */,
F8938512163AD5CE0085C3BB /* FirstViewController.m */, F8C000D5163B6B7300654C1E /* DemoRootViewController.m */,
F8938514163AD5D70085C3BB /* SecondViewController.h */,
F8938515163AD5D70085C3BB /* SecondViewController.m */,
F8938517163AD5E10085C3BB /* ThirdViewController.h */,
F8938518163AD5E10085C3BB /* ThirdViewController.m */,
F893845E163AD2BE0085C3BB /* Supporting Files */, F893845E163AD2BE0085C3BB /* Supporting Files */,
); );
path = Demo; path = Demo;
Expand All @@ -150,6 +144,8 @@
F893845E163AD2BE0085C3BB /* Supporting Files */ = { F893845E163AD2BE0085C3BB /* Supporting Files */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
F8C000CE163B67DF00654C1E /* cellBg@2x.png */,
F8C000D2163B691E00654C1E /* cellBgSelected@2x.png */,
F893845F163AD2BE0085C3BB /* Demo-Info.plist */, F893845F163AD2BE0085C3BB /* Demo-Info.plist */,
F8938460163AD2BE0085C3BB /* InfoPlist.strings */, F8938460163AD2BE0085C3BB /* InfoPlist.strings */,
F8938463163AD2BE0085C3BB /* main.m */, F8938463163AD2BE0085C3BB /* main.m */,
Expand Down Expand Up @@ -267,6 +263,8 @@
F8938506163AD49E0085C3BB /* PaperFoldResources.bundle in Resources */, F8938506163AD49E0085C3BB /* PaperFoldResources.bundle in Resources */,
F8938509163AD49E0085C3BB /* swipe_guide.psd in Resources */, F8938509163AD49E0085C3BB /* swipe_guide.psd in Resources */,
F893850A163AD49E0085C3BB /* swipe_guide2.psd in Resources */, F893850A163AD49E0085C3BB /* swipe_guide2.psd in Resources */,
F8C000CF163B67DF00654C1E /* cellBg@2x.png in Resources */,
F8C000D3163B691E00654C1E /* cellBgSelected@2x.png in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand All @@ -289,10 +287,8 @@
F893850B163AD49E0085C3BB /* ShadowView.m in Sources */, F893850B163AD49E0085C3BB /* ShadowView.m in Sources */,
F893850C163AD49E0085C3BB /* TouchThroughUIView.m in Sources */, F893850C163AD49E0085C3BB /* TouchThroughUIView.m in Sources */,
F893850D163AD49E0085C3BB /* UIView+Screenshot.m in Sources */, F893850D163AD49E0085C3BB /* UIView+Screenshot.m in Sources */,
F8938513163AD5CE0085C3BB /* FirstViewController.m in Sources */,
F8938516163AD5D70085C3BB /* SecondViewController.m in Sources */,
F8938519163AD5E20085C3BB /* ThirdViewController.m in Sources */,
F893853C163AD8680085C3BB /* DemoMenuController.m in Sources */, F893853C163AD8680085C3BB /* DemoMenuController.m in Sources */,
F8C000D6163B6B7300654C1E /* DemoRootViewController.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down
26 changes: 9 additions & 17 deletions Demo/Demo/AppDelegate.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,36 +7,28 @@
// //


#import "AppDelegate.h" #import "AppDelegate.h"
#import "FirstViewController.h" #import "DemoMenuController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"


@implementation AppDelegate @implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


_menuController = [[DemoMenuController alloc] initWithMenuWidth:250.0]; _menuController = [[DemoMenuController alloc] initWithMenuWidth:250.0 numberOfFolds:3];
[_menuController setDelegate:self]; [_menuController setDelegate:self];
[self.window setRootViewController:_menuController]; [self.window setRootViewController:_menuController];


NSMutableArray *viewControllers = [NSMutableArray array]; NSMutableArray *viewControllers = [NSMutableArray array];


FirstViewController *firstViewController = [[FirstViewController alloc] init]; for (int i=0; i<8; i++)
[firstViewController setTitle:@"First View Controller"]; {
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; DemoMenuController *rootViewController = [[DemoMenuController alloc] init];
[viewControllers addObject:firstNavController]; [rootViewController setTitle:[NSString stringWithFormat:@"Root VC %i", i+1]];
UINavigationController *rootNavController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[viewControllers addObject:rootNavController];
}


SecondViewController *secondViewController = [[SecondViewController alloc] init];
[secondViewController setTitle:@"Second View Controller"];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[viewControllers addObject:secondNavController];

ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
[thirdViewController setTitle:@"Third View Controller"];
UINavigationController *thirdNavController = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
[viewControllers addObject:thirdNavController];


[_menuController setViewControllers:viewControllers]; [_menuController setViewControllers:viewControllers];


Expand Down
53 changes: 43 additions & 10 deletions Demo/Demo/DemoMenuController.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,25 +14,58 @@ @interface DemoMenuController ()


@implementation DemoMenuController @implementation DemoMenuController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (id)initWithMenuWidth:(float)menuWidth numberOfFolds:(int)numberOfFolds
{ {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; self = [super initWithMenuWidth:menuWidth numberOfFolds:numberOfFolds];
if (self) { if (self)
// Custom initialization {
UIView *tableBgView = [[UIView alloc] init];
[tableBgView setBackgroundColor:[UIColor colorWithRed:0.170 green:0.166 blue:0.175 alpha:1.000]];
[self.menuTableView setBackgroundView:tableBgView];
[self.menuTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
} }
return self; return self;
} }


- (void)viewDidLoad - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
[super viewDidLoad]; return 50;
// Do any additional setup after loading the view.
} }


- (void)didReceiveMemoryWarning /**
* Override the method to customize cells
*/
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
[super didReceiveMemoryWarning]; if (tableView==self.menuTableView)
// Dispose of any resources that can be recreated. {
static NSString *identifier = @"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
[[cell textLabel] setTextColor:[UIColor whiteColor]];
[[cell textLabel] setHighlightedTextColor:[UIColor blackColor]];

UIImageView *bgView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"cellBg.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:20]];
[cell setBackgroundView:bgView];
UIImageView *sBgView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"cellBgSelected.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:20]];
[cell setSelectedBackgroundView:sBgView];

}

UIViewController *viewController = self.viewControllers[indexPath.row];
[cell.textLabel setText:viewController.title];

if (indexPath.row==self.selectedIndex)
{
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}

return cell;
}
else return nil;
} }



@end @end
13 changes: 13 additions & 0 deletions Demo/Demo/DemoRootViewController.h
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DemoRootViewController.h
// Demo
//
// Created by honcheng on 27/10/12.
// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface DemoRootViewController : UIViewController

@end
Original file line number Original file line Diff line number Diff line change
@@ -1,18 +1,18 @@
// //
// ThirdViewController.m // DemoRootViewController.m
// Demo // Demo
// //
// Created by honcheng on 26/10/12. // Created by honcheng on 27/10/12.
// Copyright (c) 2012 Hon Cheng Muh. All rights reserved. // Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
// //


#import "ThirdViewController.h" #import "DemoRootViewController.h"


@interface ThirdViewController () @interface DemoRootViewController ()


@end @end


@implementation ThirdViewController @implementation DemoRootViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{ {
Expand Down
13 changes: 0 additions & 13 deletions Demo/Demo/FirstViewController.h

This file was deleted.

38 changes: 0 additions & 38 deletions Demo/Demo/FirstViewController.m

This file was deleted.

13 changes: 0 additions & 13 deletions Demo/Demo/SecondViewController.h

This file was deleted.

38 changes: 0 additions & 38 deletions Demo/Demo/SecondViewController.m

This file was deleted.

13 changes: 0 additions & 13 deletions Demo/Demo/ThirdViewController.h

This file was deleted.

Binary file added Demo/Demo/cellBg@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Demo/cellBgSelected@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Resources/cellBg.psd
Binary file not shown.
8 changes: 7 additions & 1 deletion PaperFoldMenuController/PaperFoldMenuController.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,5 +54,11 @@
* This method initialize the view controller with * This method initialize the view controller with
* the width of the menu table view on the left * the width of the menu table view on the left
*/ */
- (id)initWithMenuWidth:(float)menuWidth; - (id)initWithMenuWidth:(float)menuWidth numberOfFolds:(int)numberOfFolds;
/**
* This method fold/unfolds to hide/reveal the menuTableView
* @param show A boolean value to indicate if the menu should be shown or hidden
* @param animated A boolean value to indicate if the folding/unfolding should be animated
*/
- (void)showMenu:(BOOL)show animated:(BOOL)animated;
@end @end
Loading

0 comments on commit f14c253

Please sign in to comment.