Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue #152 & improved iOS 7 status bar view #153

Merged
merged 1 commit into from
Jan 28, 2014
Merged
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
106 changes: 48 additions & 58 deletions MMDrawerController/MMDrawerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UINavigationBar * navBar = [self navigationBarContainedWithinSubviewsOfView:self];
CGRect navBarFrame = [navBar convertRect:navBar.frame toView:self];
if((self.centerInteractionMode == MMDrawerOpenCenterInteractionModeNavigationBarOnly &&
CGRectContainsPoint(navBarFrame, point) == NO) ||
CGRectContainsPoint(navBarFrame, point) == NO) ||
self.centerInteractionMode == MMDrawerOpenCenterInteractionModeNone){
hitView = nil;
}
Expand Down Expand Up @@ -130,7 +130,6 @@ @interface MMDrawerController () <UIGestureRecognizerDelegate>{

@property (nonatomic, strong) UIView * childControllerContainerView;
@property (nonatomic, strong) MMDrawerCenterContainerView * centerContainerView;
@property (nonatomic, strong) UIView * dummyStatusBarView;

@property (nonatomic, assign) CGRect startingPanRect;
@property (nonatomic, copy) MMDrawerControllerDrawerVisualStateBlock drawerVisualState;
Expand Down Expand Up @@ -199,36 +198,36 @@ - (void)encodeRestorableStateWithCoder:(NSCoder *)coder{
if (self.leftDrawerViewController){
[coder encodeObject:self.leftDrawerViewController forKey:MMDrawerLeftDrawerKey];
}

if (self.rightDrawerViewController){
[coder encodeObject:self.rightDrawerViewController forKey:MMDrawerRightDrawerKey];
}

if (self.centerViewController){
[coder encodeObject:self.centerViewController forKey:MMDrawerCenterKey];
}

[coder encodeInteger:self.openSide forKey:MMDrawerOpenSideKey];
}

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder{
UIViewController *controller;
MMDrawerSide openside;

[super decodeRestorableStateWithCoder:coder];

if ((controller = [coder decodeObjectForKey:MMDrawerLeftDrawerKey])){
self.leftDrawerViewController = [coder decodeObjectForKey:MMDrawerLeftDrawerKey];
}

if ((controller = [coder decodeObjectForKey:MMDrawerRightDrawerKey])){
self.rightDrawerViewController = controller;
}

if ((controller = [coder decodeObjectForKey:MMDrawerCenterKey])){
self.centerViewController = controller;
}

if ((openside = [coder decodeIntegerForKey:MMDrawerOpenSideKey])){
[self openDrawerSide:openside animated:false completion:nil];
}
Expand All @@ -241,11 +240,11 @@ -(void)toggleDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated complet
}
else {
if((drawerSide == MMDrawerSideLeft &&
self.openSide == MMDrawerSideLeft) ||
self.openSide == MMDrawerSideLeft) ||
(drawerSide == MMDrawerSideRight &&
self.openSide == MMDrawerSideRight)){
[self closeDrawerAnimated:animated completion:completion];
}
self.openSide == MMDrawerSideRight)){
[self closeDrawerAnimated:animated completion:completion];
}
else if(completion){
completion(NO);
}
Expand Down Expand Up @@ -473,36 +472,36 @@ -(void)setCenterViewController:(UIViewController *)newCenterViewController withF
[sideDrawerViewController.view setFrame:self.childControllerContainerView.bounds];
}
completion:^(BOOL finished) {

CGRect oldCenterRect = self.centerContainerView.frame;
[self setCenterViewController:newCenterViewController animated:animated];
[oldCenterViewController endAppearanceTransition];
[self.centerContainerView setFrame:oldCenterRect];
[self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:1.0];
[self.centerViewController beginAppearanceTransition:YES animated:animated];
[sideDrawerViewController beginAppearanceTransition:NO animated:animated];
[UIView
animateWithDuration:[self animationDurationForAnimationDistance:CGRectGetWidth(self.childControllerContainerView.bounds)]
delay:MMDrawerDefaultFullAnimationDelay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.centerContainerView setFrame:self.childControllerContainerView.bounds];
[self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:0.0];
}
completion:^(BOOL finished) {
[self.centerViewController endAppearanceTransition];
[self.centerViewController didMoveToParentViewController:self];
[sideDrawerViewController endAppearanceTransition];
[self resetDrawerVisualStateForDrawerSide:self.openSide];

[sideDrawerViewController.view setFrame:sideDrawerViewController.mm_visibleDrawerFrame];

[self setOpenSide:MMDrawerSideNone];

if(completion){
completion(finished);
}
}];
[UIView
animateWithDuration:[self animationDurationForAnimationDistance:CGRectGetWidth(self.childControllerContainerView.bounds)]
delay:MMDrawerDefaultFullAnimationDelay
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.centerContainerView setFrame:self.childControllerContainerView.bounds];
[self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:0.0];
}
completion:^(BOOL finished) {
[self.centerViewController endAppearanceTransition];
[self.centerViewController didMoveToParentViewController:self];
[sideDrawerViewController endAppearanceTransition];
[self resetDrawerVisualStateForDrawerSide:self.openSide];
[sideDrawerViewController.view setFrame:sideDrawerViewController.mm_visibleDrawerFrame];
[self setOpenSide:MMDrawerSideNone];
if(completion){
completion(finished);
}
}];
}];
}
else {
Expand Down Expand Up @@ -641,9 +640,9 @@ -(BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers{

- (void)viewDidLoad {
[super viewDidLoad];

[self.childControllerContainerView setBackgroundColor:[UIColor blackColor]];

[self setupGestureRecognizers];
}

Expand Down Expand Up @@ -827,7 +826,6 @@ -(void)setShowsStatusBarBackgroundView:(BOOL)showsDummyStatusBar{
frame.size.height = CGRectGetHeight(self.view.bounds);
}
[self.childControllerContainerView setFrame:frame];
[self.dummyStatusBarView setHidden:!showsDummyStatusBar];
}
}
else {
Expand All @@ -837,7 +835,7 @@ -(void)setShowsStatusBarBackgroundView:(BOOL)showsDummyStatusBar{

-(void)setStatusBarViewBackgroundColor:(UIColor *)dummyStatusBarColor{
_statusBarViewBackgroundColor = dummyStatusBarColor;
[self.dummyStatusBarView setBackgroundColor:_statusBarViewBackgroundColor];
[self.view setBackgroundColor:_statusBarViewBackgroundColor];
}

#pragma mark - Getters
Expand Down Expand Up @@ -873,26 +871,18 @@ -(CGFloat)visibleRightDrawerWidth{
}

-(UIView*)childControllerContainerView{
if(_childControllerContainerView == nil){
_childControllerContainerView = [[UIView alloc] initWithFrame:self.view.bounds];
[_childControllerContainerView setBackgroundColor:[UIColor clearColor]];
[_childControllerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[self.view addSubview:_childControllerContainerView];
if (_childControllerContainerView == nil) {
CGRect b = self.view.bounds;
if(_childControllerContainerView == nil) {
_childControllerContainerView = [[UIView alloc] initWithFrame:b];
[_childControllerContainerView setBackgroundColor:[UIColor clearColor]];
[_childControllerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[self.view addSubview:_childControllerContainerView];
}
}
return _childControllerContainerView;
}

-(UIView*)dummyStatusBarView{
if(_dummyStatusBarView==nil){
_dummyStatusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 20)];
[_dummyStatusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[_dummyStatusBarView setBackgroundColor:self.statusBarViewBackgroundColor];
[_dummyStatusBarView setHidden:!_showsStatusBarBackgroundView];
[self.view addSubview:_dummyStatusBarView];
}
return _dummyStatusBarView;
}

-(UIColor*)statusBarViewBackgroundColor{
if(_statusBarViewBackgroundColor == nil){
_statusBarViewBackgroundColor = [UIColor blackColor];
Expand Down Expand Up @@ -940,7 +930,7 @@ -(void)panGestureCallback:(UIPanGestureRecognizer *)panGesture{
UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:self.openSide];
[sideDrawerViewController beginAppearanceTransition:NO animated:NO];
[sideDrawerViewController endAppearanceTransition];

//Drawer is about to become visible
[self prepareToPresentDrawer:visibleSide animated:NO];
[visibleSideDrawerViewController endAppearanceTransition];
Expand Down Expand Up @@ -1130,7 +1120,7 @@ -(void)prepareToPresentDrawer:(MMDrawerSide)drawer animated:(BOOL)animated{

UIViewController * sideDrawerViewControllerToPresent = [self sideDrawerViewControllerForSide:drawer];
UIViewController * sideDrawerViewControllerToHide = [self sideDrawerViewControllerForSide:drawerToHide];

[self.childControllerContainerView sendSubviewToBack:sideDrawerViewControllerToHide.view];
[sideDrawerViewControllerToHide.view setHidden:YES];
[sideDrawerViewControllerToPresent.view setHidden:NO];
Expand Down