Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 60 additions & 9 deletions KitchenSink/ExampleFiles/MMExampleCenterTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import <QuartzCore/QuartzCore.h>

typedef NS_ENUM(NSInteger, MMCenterViewControllerSection){
MMCenterViewControllerSectionStatusBarBackgroundState,
MMCenterViewControllerSectionLeftViewState,
MMCenterViewControllerSectionLeftDrawerAnimation,
MMCenterViewControllerSectionRightViewState,
Expand Down Expand Up @@ -78,9 +79,9 @@ - (void)viewDidLoad

if(OSVersionIsAtLeastiOS7()){
UIColor * barColor = [UIColor
colorWithRed:247.0/255.0
green:249.0/255.0
blue:250.0/255.0
colorWithRed:217.0/255.0
green:219.0/255.0
blue:220.0/255.0
alpha:1.0];
[self.navigationController.navigationBar setBarTintColor:barColor];
}
Expand Down Expand Up @@ -145,7 +146,7 @@ -(void)contentSizeDidChange:(NSString *)size{

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 4;
return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Expand All @@ -158,6 +159,8 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
case MMCenterViewControllerSectionLeftViewState:
case MMCenterViewControllerSectionRightViewState:
return 1;
case MMCenterViewControllerSectionStatusBarBackgroundState:
return 3;
default:
return 0;
}
Expand Down Expand Up @@ -186,6 +189,29 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
alpha:1.0];

switch (indexPath.section) {
case MMCenterViewControllerSectionStatusBarBackgroundState:
if(self.mm_drawerController.statusBarBackgroundViewMode == indexPath.row){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[cell.textLabel setTextColor:selectedColor];
}
else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
[cell.textLabel setTextColor:unselectedColor];
}
switch (indexPath.row) {
case MMStatusBarBackgroundViewModeNone:
[cell.textLabel setText:@"None"];
break;
case MMStatusBarBackgroundViewModeOpaque:
[cell.textLabel setText:@"Opaque"];
break;
case MMStatusBarBackgroundViewModeVariable:
[cell.textLabel setText:@"Variable"];
break;
default:
break;
}
break;
case MMCenterViewControllerSectionLeftDrawerAnimation:
case MMCenterViewControllerSectionRightDrawerAnimation:{
MMDrawerAnimationType animationTypeForSection;
Expand Down Expand Up @@ -258,6 +284,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
switch (section) {
case MMCenterViewControllerSectionStatusBarBackgroundState:
return @"Status Bar Background View Mode";
case MMCenterViewControllerSectionLeftDrawerAnimation:
return @"Left Drawer Animation";
case MMCenterViewControllerSectionRightDrawerAnimation:
Expand All @@ -274,7 +302,21 @@ -(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSIntege

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MMExampleCenterTableViewController * center;
UINavigationController * nav;

switch (indexPath.section) {
case MMCenterViewControllerSectionStatusBarBackgroundState:
[self.mm_drawerController setStatusBarBackgroundViewMode:indexPath.row];

center = [[MMExampleCenterTableViewController alloc] init];
nav = [[MMNavigationController alloc] initWithRootViewController:center];
self.mm_drawerController.centerViewController = nav;

[tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
break;
case MMCenterViewControllerSectionLeftDrawerAnimation:
case MMCenterViewControllerSectionRightDrawerAnimation:{
if(indexPath.section == MMCenterViewControllerSectionLeftDrawerAnimation){
Expand Down Expand Up @@ -322,15 +364,24 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
else {
if(drawerSide == MMDrawerSideLeft){
UIViewController * vc = [[MMExampleLeftSideDrawerViewController alloc] init];
UINavigationController * navC = [[MMNavigationController alloc] initWithRootViewController:vc];
[self.mm_drawerController setLeftDrawerViewController:navC];
if(OSVersionIsAtLeastiOS7()){
UINavigationController * navC = [[MMNavigationController alloc] initWithRootViewController:vc];
[self.mm_drawerController setLeftDrawerViewController:navC];
}
else {
[self.mm_drawerController setLeftDrawerViewController:vc];
}
[self setupLeftMenuButton];

}
else if(drawerSide == MMDrawerSideRight){
UIViewController * vc = [[MMExampleRightSideDrawerViewController alloc] init];
UINavigationController * navC = [[MMNavigationController alloc] initWithRootViewController:vc];
[self.mm_drawerController setRightDrawerViewController:navC];
if(drawerSide == MMDrawerSideLeft){
UINavigationController * navC = [[MMNavigationController alloc] initWithRootViewController:vc];
[self.mm_drawerController setRightDrawerViewController:navC];
}
else {
[self.mm_drawerController setRightDrawerViewController:vc];
}
[self setupRightMenuButton];
}
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
Expand Down
20 changes: 17 additions & 3 deletions MMDrawerController/MMDrawerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ typedef NS_ENUM(NSInteger, MMDrawerOpenCenterInteractionMode) {
MMDrawerOpenCenterInteractionModeNavigationBarOnly,
};

typedef NS_ENUM(NSInteger, MMStatusBarBackgroundViewMode) {
MMStatusBarBackgroundViewModeNone = 0,
MMStatusBarBackgroundViewModeVariable,
MMStatusBarBackgroundViewModeOpaque,
};

@class MMDrawerController;
typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible);

Expand Down Expand Up @@ -201,11 +207,13 @@ typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * dr
@property (nonatomic, assign) BOOL showsShadow;

/**
The flag determining if a custom background view should appear beneath the status bar, forcing the child content to be drawn lower than the status bar. This property is only available for > iOS 7.0 to take into account for the new behavior of the status bar.
The value determining if a custom background view will appear beneath the status bar. This property is only available for > iOS 7.0 to take into account for the new behavior of the status bar.

If set to `MMStatusBarBackgroundViewModeOpaque` the child content will be drawn lower than the status bar.

By default, this is set to NO. If running on < iOS 7.0, it will always return NO.
By default, this is set to `MMStatusBarBackgroundViewModeNone`. If running on < iOS 7.0, it will always return `MMStatusBarBackgroundViewModeNone`.
*/
@property (nonatomic, assign) BOOL showsStatusBarBackgroundView;
@property (nonatomic, assign) MMStatusBarBackgroundViewMode statusBarBackgroundViewMode;

/**
The color of the status bar background view if `showsStatusBarBackgroundView` is set to YES. This value is ignored in < iOS 7.0.
Expand Down Expand Up @@ -410,4 +418,10 @@ typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * dr
*/
-(void)setGestureShouldRecognizeTouchBlock:(BOOL(^)(MMDrawerController * drawerController, UIGestureRecognizer * gesture, UITouch * touch))gestureShouldRecognizeTouchBlock;

/**
Method create for backwards compatibility. When called with param YES, `statusBarBackgroundViewMode` will be set to `MMStatusBarBackgroundViewModeOpaque`.
*/
-(BOOL)showsStatusBarBackgroundView;
-(void)setShowsStatusBarBackgroundView:(BOOL)showsBackgroundFlag;

@end
42 changes: 35 additions & 7 deletions MMDrawerController/MMDrawerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ -(void)closeDrawerAnimated:(BOOL)animated velocity:(CGFloat)velocity animationOp
[self setNeedsStatusBarAppearanceUpdateIfSupported];
[self.centerContainerView setFrame:newFrame];
[self updateDrawerVisualStateForDrawerSide:visibleSide percentVisible:0.0];
[self updateStatusBarBackgroundViewWithAlpha:0.0f];
}
completion:^(BOOL finished) {
[sideDrawerViewController endAppearanceTransition];
Expand Down Expand Up @@ -356,6 +357,7 @@ -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated velocity:
[self setNeedsStatusBarAppearanceUpdateIfSupported];
[self.centerContainerView setFrame:newFrame];
[self updateDrawerVisualStateForDrawerSide:drawerSide percentVisible:1.0];
[self updateStatusBarBackgroundViewWithAlpha:1.0f];
}
completion:^(BOOL finished) {
//End the appearance transition if it already wasn't open.
Expand Down Expand Up @@ -520,6 +522,7 @@ -(void)setCenterViewController:(UIViewController *)newCenterViewController withF
animations:^{
[self.centerContainerView setFrame:self.childControllerContainerView.bounds];
[self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:0.0];
[self updateStatusBarBackgroundViewWithAlpha:0.0f];
}
completion:^(BOOL finished) {
if (forwardAppearanceMethodsToCenterViewController) {
Expand Down Expand Up @@ -878,27 +881,30 @@ -(void)setMaximumRightDrawerWidth:(CGFloat)maximumRightDrawerWidth{
[self setMaximumRightDrawerWidth:maximumRightDrawerWidth animated:NO completion:nil];
}

-(void)setShowsStatusBarBackgroundView:(BOOL)showsDummyStatusBar{
-(void)setStatusBarBackgroundViewMode:(MMStatusBarBackgroundViewMode)dummyStatusBarMode{
NSArray *sysVersion = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
float majorVersion = [[sysVersion objectAtIndex:0] floatValue];
if (majorVersion >= 7){
if(showsDummyStatusBar!=_showsStatusBarBackgroundView){
_showsStatusBarBackgroundView = showsDummyStatusBar;
if(dummyStatusBarMode!=_statusBarBackgroundViewMode){
_statusBarBackgroundViewMode = dummyStatusBarMode;
CGRect frame = self.childControllerContainerView.frame;
if(_showsStatusBarBackgroundView){
if(_statusBarBackgroundViewMode == MMStatusBarBackgroundViewModeOpaque){
frame.origin.y = 20;
frame.size.height = CGRectGetHeight(self.view.bounds)-20;
[self.dummyStatusBarView setAlpha:1.0];
}
else {
frame.origin.y = 0;
frame.size.height = CGRectGetHeight(self.view.bounds);
[self updateStatusBarBackgroundViewAlpha];
}
[self setNeedsStatusBarAppearanceUpdateIfSupported];
[self.childControllerContainerView setFrame:frame];
[self.dummyStatusBarView setHidden:!showsDummyStatusBar];
[self.dummyStatusBarView setHidden:!dummyStatusBarMode];
}
}
else {
_showsStatusBarBackgroundView = NO;
_statusBarBackgroundViewMode = MMStatusBarBackgroundViewModeNone;
}
}

Expand Down Expand Up @@ -970,7 +976,7 @@ -(UIView*)dummyStatusBarView{
_dummyStatusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 20)];
[_dummyStatusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[_dummyStatusBarView setBackgroundColor:self.statusBarViewBackgroundColor];
[_dummyStatusBarView setHidden:!_showsStatusBarBackgroundView];
[_dummyStatusBarView setHidden:!_statusBarBackgroundViewMode];
[self.view addSubview:_dummyStatusBarView];
}
return _dummyStatusBarView;
Expand Down Expand Up @@ -1042,6 +1048,7 @@ -(void)panGestureCallback:(UIPanGestureRecognizer *)panGesture{
[self setOpenSide:MMDrawerSideNone];
}

[self updateStatusBarBackgroundViewWithAlpha:percentVisible];
[self updateDrawerVisualStateForDrawerSide:visibleSide percentVisible:percentVisible];

[self.centerContainerView setCenter:CGPointMake(CGRectGetMidX(newFrame), CGRectGetMidY(newFrame))];
Expand All @@ -1065,6 +1072,14 @@ -(void)panGestureCallback:(UIPanGestureRecognizer *)panGesture{
}

#pragma mark - iOS 7 Status Bar Helpers
-(BOOL)showsStatusBarBackgroundView{
return _statusBarBackgroundViewMode != MMStatusBarBackgroundViewModeNone;
}

-(void)setShowsStatusBarBackgroundView:(BOOL)showsBackgroundFlag{
_statusBarBackgroundViewMode=showsBackgroundFlag?MMStatusBarBackgroundViewModeOpaque:MMStatusBarBackgroundViewModeNone;
}

-(UIViewController*)childViewControllerForStatusBarStyle{
return [self childViewControllerForSide:self.openSide];
}
Expand All @@ -1079,6 +1094,19 @@ -(void)setNeedsStatusBarAppearanceUpdateIfSupported{
}
}

- (void)updateStatusBarBackgroundViewAlpha{
CGFloat visibleDrawerPoints = CGRectGetMinX(self.centerContainerView.frame);
CGFloat percentVisble = MAX(0.0,visibleDrawerPoints/self.maximumLeftDrawerWidth);
[self updateStatusBarBackgroundViewWithAlpha:percentVisble];
}

-(void)updateStatusBarBackgroundViewWithAlpha:(CGFloat)alpha
{
if (_statusBarBackgroundViewMode == MMStatusBarBackgroundViewModeVariable) {
[self.dummyStatusBarView setAlpha:alpha];
}
}

#pragma mark - Animation helpers
-(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:(void(^)(BOOL finished))completion{
CGFloat currentOriginX = CGRectGetMinX(self.centerContainerView.frame);
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ If you do not want the drawer controller to consult the child view controllers f
###Custom Status Bar Background View
If you have a contrasting colors between your center view controller and your drawer controllers, the new iOS 7 status bar handling could cause your application to look less than ideal. Starting with iOS 7, `MMDrawerController` supports drawing a custom status bar area at the top of the screen, to give you an area to display the status bar with a constant color, while allowing you to draw custom content below the status bar without worrying about the color of your navigation bars or the top of your content running up underneath the status bar. Using the feature essentially mimics <= iOS 6.X behavior.

To enable a custom status bar, simple set `showsStatusBarBackgroundView` to `YES`. By default, this will draw a black a view underneath the status bar, and adjust your to content to be laid out lower than the status bar. If you would like a custom status background color, you can set `statusBarViewBackgroundColor` to whatever color you desire.

You can set `statusBarBackgroundViewMode` to one of the following modes to control the custom status bar background:
* **MMStatusBarBackgroundViewModeNone** is the default value, and doesn't add any backgroud to the status bar.
* **MMStatusBarBackgroundViewModeVariable** adds a status bar background view that appears only when a drawer is open. The background view fades in as the drawer opens.
* **MMStatusBarBackgroundViewModeOpaque** adds a opaque status bar background view that appears at all times.

Additionally, setting the old property `showsStatusBarBackgroundView` to NO will set `statusBarBackgroundViewMode` to **MMStatusBarBackgroundViewModeNone** and YES will set it to **MMStatusBarBackgroundViewModeOpaque**.

If you would like a custom status background color, you can set `statusBarViewBackgroundColor` to whatever color you desire.

---
##Subclassing
Expand Down