Skip to content

Commit

Permalink
ios7
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Lluch committed Jul 7, 2013
1 parent cfa42f4 commit cf154fc
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 988 deletions.
5 changes: 3 additions & 2 deletions RevealControllerExample/RevealControllerProject/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
FrontViewController *frontViewController = [[FrontViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:navigationController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ @implementation RearViewController

@synthesize rearTableView = _rearTableView;


#pragma mark - View lifecycle


- (void)viewDidLoad
{
[super viewDidLoad];

self.title = NSLocalizedString(@"Rear View", nil);
}


#pragma marl - UITableView Data Source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="20">
<rect key="frame" x="0.0" y="44" width="320" height="416"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<outlet property="dataSource" destination="-1" id="22"/>
<outlet property="delegate" destination="-1" id="23"/>
</connections>
</tableView>
<navigationBar contentMode="scaleToFill" barStyle="black" id="18">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<items>
<navigationItem title="Rear View" id="19"/>
</items>
</navigationBar>
</subviews>
<color key="backgroundColor" white="0.19782162410000001" alpha="1" colorSpace="calibratedWhite"/>
</view>
</objects>
<classes>
<class className="RearViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/RearViewController.h"/>
<relationships>
<relationship kind="outlet" name="rearTableView" candidateClass="UITableView"/>
</relationships>
</class>
</classes>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

FrontViewController *frontViewController = [[FrontViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];

UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearViewController frontViewController:navigationController];
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];

mainRevealController.delegate = self;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@interface RearViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) IBOutlet UITableView *rearTableView;
@property (nonatomic, retain) IBOutlet UIToolbar *rearToolBar;
//@property (nonatomic, retain) IBOutlet UIToolbar *rearToolBar;


@end
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,33 @@ @implementation RearViewController
* following hierarchy is created:
*
* - SWRevealController is parent of:
* - - UINavigationController is parent of:
* - - - FrontViewController
* - 1 UINavigationController is parent of:
* - - 1.1 RearViewController
* - 2 UINavigationController is parent of:
* - - 2.1 FrontViewController
*
* In the second scenario a MapViewController is contained inside of a UINavigationController.
* And the UINavigationController is contained inside of a SWRevealController. Thus the
* following hierarchy is created:
*
* - SWRevealController is parent of:
* - - UINavigationController is parent of:
* - - - MapViewController
* - 1 UINavigationController is parent of:
* - - 1.1 RearViewController
* - 2 UINavigationController is parent of:
* - - 1.2 MapViewController
*
* In the third scenario a SWRevealViewController is contained directly inside of another.
* SWRevealController. The second SWRevealController can in turn contain anything.
* contain any of the above Thus the
* following hierarchy is created:
* SWRevealController. Thus the following hierarchy is created:
*
* - SWRevealController is parent of:
* - - SWRevealController
* - 1 UINavigationController is parent of:
* - - 1.1 RearViewController
* - 2 SWRevealController
*
* If you set ShouldContainRevealControllerInNavigator to true, a UINavigationController will be used to
* contain child SWRevealControllers, thus producing a vertical cascade effect on the user interface
* The second SWRevealController on the third scenario can in turn contain anything.
* On this example it may recursively contain any of the above, including again the third one
*/

#define ShouldContainRevealControllerInNavigator false

- (void)viewDidLoad
{
[super viewDidLoad];
Expand All @@ -80,14 +82,12 @@ - (void)viewDidLoad
SWRevealViewController *parentRevealController = self.revealViewController;
SWRevealViewController *grandParentRevealController = parentRevealController.revealViewController;

UIBarButtonItem *titleButtonItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:nil action:0];
UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:0];
UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"]
style:UIBarButtonItemStyleBordered target:grandParentRevealController action:@selector(revealToggle:)];

// if we have a reveal controller as a grand parent, this means we are are being added as a
// child of a detail (child) reveal controller, so we add a gesture recognizer provided by our grand parent to our
// toolbar as well as a "reveal" button
// navigation bar as well as a "reveal" button
if ( grandParentRevealController )
{
// to present a title, we count the number of ancestor reveal controllers we have, this is of course
Expand All @@ -98,31 +98,16 @@ - (void)viewDidLoad
level++;

NSString *title = [NSString stringWithFormat:@"Detail Level %d", level];

// if our parent reveal controller was contained in a navigation controller we set the title, gesture, and button
// on its navigation bar
if ([parentRevealController navigationController])
{
[parentRevealController.navigationController.navigationBar addGestureRecognizer:grandParentRevealController.panGestureRecognizer];
parentRevealController.navigationItem.leftBarButtonItem = revealButtonItem;
parentRevealController.navigationItem.title = title;
}

// otherwise, our reveal controller was directly inserted in the hierarchy so we use our toolbar to set the
// controls
else
{
[_rearToolBar addGestureRecognizer:grandParentRevealController.panGestureRecognizer];
[titleButtonItem setTitle:title];
[_rearToolBar setItems:@[revealButtonItem,spaceButtonItem,titleButtonItem,spaceButtonItem]];
}

[self.navigationController.navigationBar addGestureRecognizer:grandParentRevealController.panGestureRecognizer];
self.navigationItem.leftBarButtonItem = revealButtonItem;
self.navigationItem.title = title;
}

// otherwise, we are in the top reveal controller, so we just add a title
else
{
[titleButtonItem setTitle:@"Master"];
[_rearToolBar setItems:@[spaceButtonItem,titleButtonItem,spaceButtonItem]];
self.navigationItem.title = @"Master";
}
}

Expand Down Expand Up @@ -173,15 +158,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Grab a handle to the reveal controller, as if you'd do with a navigtion controller via self.navigationController.
SWRevealViewController *revealController = [self revealViewController];
UIViewController *frontViewController = revealController.frontViewController;
UINavigationController *frontNavigationController =nil;

if ( [frontViewController isKindOfClass:[UINavigationController class]] )
frontNavigationController = (id)frontViewController;


NSInteger row = indexPath.row;

// Here you'd implement some of your own logic... I simply take for granted that the first row (=0) corresponds to the "FrontViewController".
Expand Down Expand Up @@ -234,18 +217,18 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
{
FrontViewController *frontViewController = [[FrontViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];

UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

SWRevealViewController *childRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearViewController frontViewController:navigationController];
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];

revealController.bounceBackOnOverdraw = NO;
[childRevealController setFrontViewPosition:FrontViewPositionRight animated:NO];

#if ShouldContainRevealControllerInNavigator == false
// at this point we simply set the front view controller of our revealController to the next revealController
[revealController setFrontViewController:childRevealController animated:YES];
#else
UINavigationController *revealNavController = [[UINavigationController alloc] initWithRootViewController:childRevealController];
[revealController setFrontViewController:revealNavController animated:YES];
#endif
}
else
{
Expand Down
Loading

0 comments on commit cf154fc

Please sign in to comment.