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 an issue where you would get an unbalanced appearance state for the center view controller #219

Merged
merged 1 commit into from
Feb 18, 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
34 changes: 26 additions & 8 deletions MMDrawerController/MMDrawerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated velocity:
//If animated is NO, then we need to handle all the appearance calls within this method. Otherwise,
//let the method calling this one handle proper appearance methods since they will have more context
-(void)setCenterViewController:(UIViewController *)centerViewController animated:(BOOL)animated{
if ([self.centerViewController isEqual:centerViewController]) {
return;
}

if(_centerContainerView == nil){
_centerContainerView = [[MMDrawerCenterContainerView alloc] initWithFrame:self.childControllerContainerView.bounds];
[self.centerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
Expand Down Expand Up @@ -424,16 +428,22 @@ -(void)setCenterViewController:(UIViewController *)newCenterViewController withC
//If a side drawer isn't open, there is nothing to animate...
animated = NO;
}

BOOL forwardAppearanceMethodsToCenterViewController = ([self.centerViewController isEqual:newCenterViewController] == NO);
[self setCenterViewController:newCenterViewController animated:animated];

if(animated){
[self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:1.0];
[self.centerViewController beginAppearanceTransition:YES animated:animated];
if (forwardAppearanceMethodsToCenterViewController) {
[self.centerViewController beginAppearanceTransition:YES animated:animated];
}
[self
closeDrawerAnimated:animated
completion:^(BOOL finished) {
[self.centerViewController endAppearanceTransition];
[self.centerViewController didMoveToParentViewController:self];
if (forwardAppearanceMethodsToCenterViewController) {
[self.centerViewController endAppearanceTransition];
[self.centerViewController didMoveToParentViewController:self];
}
if(completion){
completion(finished);
}
Expand All @@ -450,6 +460,8 @@ -(void)setCenterViewController:(UIViewController *)newCenterViewController withF
if(self.openSide != MMDrawerSideNone &&
animated){

BOOL forwardAppearanceMethodsToCenterViewController = ([self.centerViewController isEqual:newCenterViewController] == NO);

UIViewController * sideDrawerViewController = [self sideDrawerViewControllerForSide:self.openSide];

CGFloat targetClosePoint = 0.0f;
Expand All @@ -468,7 +480,9 @@ -(void)setCenterViewController:(UIViewController *)newCenterViewController withF
[self setAnimatingDrawer:animated];

UIViewController * oldCenterViewController = self.centerViewController;
[oldCenterViewController beginAppearanceTransition:NO animated:animated];
if(forwardAppearanceMethodsToCenterViewController ){
[oldCenterViewController beginAppearanceTransition:NO animated:animated];
}
newCenterRect.origin.x = targetClosePoint;
[UIView
animateWithDuration:firstDuration
Expand All @@ -482,10 +496,12 @@ -(void)setCenterViewController:(UIViewController *)newCenterViewController withF

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];
if(forwardAppearanceMethodsToCenterViewController) {
[oldCenterViewController endAppearanceTransition];
[self.centerViewController beginAppearanceTransition:YES animated:animated];
}
[sideDrawerViewController beginAppearanceTransition:NO animated:animated];
[UIView
animateWithDuration:[self animationDurationForAnimationDistance:CGRectGetWidth(self.childControllerContainerView.bounds)]
Expand All @@ -496,8 +512,10 @@ -(void)setCenterViewController:(UIViewController *)newCenterViewController withF
[self updateDrawerVisualStateForDrawerSide:self.openSide percentVisible:0.0];
}
completion:^(BOOL finished) {
[self.centerViewController endAppearanceTransition];
[self.centerViewController didMoveToParentViewController:self];
if (forwardAppearanceMethodsToCenterViewController) {
[self.centerViewController endAppearanceTransition];
[self.centerViewController didMoveToParentViewController:self];
}
[sideDrawerViewController endAppearanceTransition];
[self resetDrawerVisualStateForDrawerSide:self.openSide];

Expand Down