-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- JTRevealSidebarV2. A truly reusable solution which mimic the sideba…
…r pattern which used by new Facebook and Path iOS app
- Loading branch information
Showing
24 changed files
with
1,255 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// AppDelegate.h | ||
// JTRevealSidebarDemoV2 | ||
// | ||
// Created by James Apple Tang on 7/12/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// AppDelegate.m | ||
// JTRevealSidebarDemoV2 | ||
// | ||
// Created by James Apple Tang on 7/12/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "AppDelegate.h" | ||
#import "ViewController.h" | ||
|
||
@implementation AppDelegate | ||
|
||
@synthesize window = _window; | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | ||
// Override point for customization after application launch. | ||
self.window.backgroundColor = [UIColor whiteColor]; | ||
|
||
ViewController *controller = [[ViewController alloc] init]; | ||
controller.title = @"ViewController"; | ||
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller]; | ||
|
||
self.window.rootViewController = navController; | ||
[self.window makeKeyAndVisible]; | ||
return YES; | ||
} | ||
|
||
- (void)applicationWillResignActive:(UIApplication *)application | ||
{ | ||
/* | ||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
*/ | ||
} | ||
|
||
- (void)applicationDidEnterBackground:(UIApplication *)application | ||
{ | ||
/* | ||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
*/ | ||
} | ||
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application | ||
{ | ||
/* | ||
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
*/ | ||
} | ||
|
||
- (void)applicationDidBecomeActive:(UIApplication *)application | ||
{ | ||
/* | ||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
*/ | ||
} | ||
|
||
- (void)applicationWillTerminate:(UIApplication *)application | ||
{ | ||
/* | ||
Called when the application is about to terminate. | ||
Save data if appropriate. | ||
See also applicationDidEnterBackground:. | ||
*/ | ||
} | ||
|
||
@end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleIconFiles</key> | ||
<array/> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.mystcolor.${PRODUCT_NAME:rfc1034identifier}</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations~ipad</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Prefix header for all source files of the 'JTRevealSidebarDemoV2' target in the 'JTRevealSidebarDemoV2' project | ||
// | ||
|
||
#import <Availability.h> | ||
|
||
#ifndef __IPHONE_3_0 | ||
#warning "This project uses features only available in iOS SDK 3.0 and later." | ||
#endif | ||
|
||
#ifdef __OBJC__ | ||
#import <UIKit/UIKit.h> | ||
#import <Foundation/Foundation.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// NewViewController.h | ||
// JTRevealSidebarDemo | ||
// | ||
// Created by James Apple Tang on 12/12/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface NewViewController : UIViewController | ||
|
||
@property (nonatomic, strong) UILabel *label; | ||
@property (nonatomic, strong) UITableView *rightSidebarView; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// NewViewController.m | ||
// JTRevealSidebarDemo | ||
// | ||
// Created by James Apple Tang on 12/12/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "NewViewController.h" | ||
#import "UINavigationItem+JTRevealSidebarV2.h" | ||
#import "UIViewController+JTRevealSidebarV2.h" | ||
#import "JTRevealSidebarV2Delegate.h" | ||
|
||
@interface NewViewController () <JTRevealSidebarV2Delegate, UITableViewDataSource, UITableViewDelegate> | ||
@end | ||
|
||
@implementation NewViewController | ||
@synthesize label; | ||
@synthesize rightSidebarView; | ||
#pragma mark - View lifecycle | ||
|
||
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. | ||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
self.label = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 290, 30)]; | ||
[self.view addSubview:self.label]; | ||
|
||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(revealRightSidebar:)]; | ||
|
||
self.navigationItem.revealSidebarDelegate = self; | ||
} | ||
|
||
- (void)viewDidUnload | ||
{ | ||
[super viewDidUnload]; | ||
// Release any retained subviews of the main view. | ||
// e.g. self.myOutlet = nil; | ||
} | ||
|
||
#pragma mark Action | ||
|
||
- (void)revealRightSidebar:(id)sender { | ||
JTRevealedState state = JTRevealedStateRight; | ||
if (self.navigationController.revealedState == JTRevealedStateRight) { | ||
state = JTRevealedStateNo; | ||
} | ||
[self.navigationController setRevealedState:state]; | ||
} | ||
|
||
|
||
#pragma mark UITableViewDatasource | ||
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | ||
return 8; | ||
} | ||
|
||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | ||
return 1; | ||
} | ||
|
||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | ||
static NSString *cellIdentifier = @"CellIdentifier"; | ||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; | ||
if ( ! cell) { | ||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; | ||
cell.selectionStyle = UITableViewCellSelectionStyleGray; | ||
} | ||
cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; | ||
return cell; | ||
} | ||
|
||
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { | ||
if (tableView == self.rightSidebarView) { | ||
return @"RightSidebar"; | ||
} | ||
return nil; | ||
} | ||
|
||
#pragma mark UITableViewDelegate | ||
|
||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | ||
[self.navigationController setRevealedState:JTRevealedStateNo]; | ||
if (tableView == self.rightSidebarView) { | ||
self.label.text = [NSString stringWithFormat:@"Selected %d at RightSidebarView", indexPath.row]; | ||
} | ||
} | ||
|
||
|
||
#pragma mark JTRevealSidebarV2Delegate | ||
|
||
- (UIView *)viewForRightSidebar { | ||
CGRect mainFrame = [[UIScreen mainScreen] applicationFrame]; | ||
UITableView *view = self.rightSidebarView; | ||
if ( ! view) { | ||
view = self.rightSidebarView = [[UITableView alloc] initWithFrame:CGRectMake(160, mainFrame.origin.y, 160, mainFrame.size.height) style:UITableViewStyleGrouped]; | ||
view.dataSource = self; | ||
view.delegate = self; | ||
view.backgroundColor = [UIColor groupTableViewBackgroundColor]; | ||
} | ||
return view; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// LeftSidebarViewController.h | ||
// JTRevealSidebarDemo | ||
// | ||
// Created by James Apple Tang on 12/12/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@protocol SidebarViewControllerDelegate; | ||
|
||
@interface SidebarViewController : UITableViewController | ||
|
||
@property (nonatomic, assign) id <SidebarViewControllerDelegate> sidebarDelegate; | ||
|
||
@end | ||
|
||
@protocol SidebarViewControllerDelegate <NSObject> | ||
|
||
- (void)sidebarViewController:(SidebarViewController *)sidebarViewController didSelectObject:(NSObject *)object atIndexPath:(NSIndexPath *)indexPath; | ||
|
||
@optional | ||
- (NSIndexPath *)lastSelectedIndexPathForSidebarViewController:(SidebarViewController *)sidebarViewController; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// LeftSidebarViewController.m | ||
// JTRevealSidebarDemo | ||
// | ||
// Created by James Apple Tang on 12/12/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "SidebarViewController.h" | ||
|
||
|
||
@implementation SidebarViewController | ||
@synthesize sidebarDelegate; | ||
|
||
- (id)initWithStyle:(UITableViewStyle)style | ||
{ | ||
self = [super initWithStyle:style]; | ||
if (self) { | ||
// Custom initialization | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - View lifecycle | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
} | ||
|
||
- (void)viewWillAppear:(BOOL)animated { | ||
[super viewWillAppear:animated]; | ||
|
||
if ([self.sidebarDelegate respondsToSelector:@selector(lastSelectedIndexPathForSidebarViewController:)]) { | ||
NSIndexPath *indexPath = [self.sidebarDelegate lastSelectedIndexPathForSidebarViewController:self]; | ||
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; | ||
} | ||
} | ||
|
||
- (void)viewDidUnload | ||
{ | ||
[super viewDidUnload]; | ||
// Release any retained subviews of the main view. | ||
// e.g. self.myOutlet = nil; | ||
} | ||
|
||
#pragma mark - Table view data source | ||
|
||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | ||
{ | ||
return 1; | ||
} | ||
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | ||
{ | ||
return 5; | ||
} | ||
|
||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
static NSString *CellIdentifier = @"Cell"; | ||
|
||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | ||
if (cell == nil) { | ||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; | ||
} | ||
|
||
cell.textLabel.text = [NSString stringWithFormat:@"ViewController%d", indexPath.row]; | ||
|
||
return cell; | ||
} | ||
|
||
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { | ||
return self.title; | ||
} | ||
|
||
#pragma mark - Table view delegate | ||
|
||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | ||
if (self.sidebarDelegate) { | ||
NSObject *object = [NSString stringWithFormat:@"ViewController%d", indexPath.row]; | ||
[self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath]; | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.