Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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 @@ -275,7 +303,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 @@ -323,15 +365,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 @@ -359,6 +360,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 @@ -510,6 +512,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 @@ -835,27 +838,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 updateStatusBarBackgroundViewAlpa];
}
[self setNeedsStatusBarAppearanceUpdateIfSupported];
[self.childControllerContainerView setFrame:frame];
[self.dummyStatusBarView setHidden:!showsDummyStatusBar];
[self.dummyStatusBarView setHidden:!dummyStatusBarMode];
}
}
else {
_showsStatusBarBackgroundView = NO;
_statusBarBackgroundViewMode = MMStatusBarBackgroundViewModeNone;
}
}

Expand Down Expand Up @@ -922,7 +928,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 @@ -993,6 +999,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 @@ -1018,6 +1025,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 @@ -1032,6 +1047,19 @@ -(void)setNeedsStatusBarAppearanceUpdateIfSupported{
}
}

- (void)updateStatusBarBackgroundViewAlpa{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the method name

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