Created
December 26, 2014 07:35
-
-
Save akisute/e1b6176fab25ba34a2df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)removeViewController:(BOOL)animated | |
{ | |
CGRect destInitialFrame = self.destinationFrame; | |
CGRect destFinalFrame = CGRectMake(CGRectGetMaxX(destInitialFrame), | |
CGRectGetMinY(destInitialFrame), | |
CGRectGetWidth(destInitialFrame), | |
CGRectGetHeight(destInitialFrame)); | |
UIViewController *srcViewController = self.sourceViewController; | |
UIViewController *destViewController = self.destinationViewController; | |
// 1. beginAppearanceTransition:animated: | |
[srcViewController beginAppearanceTransition:YES animated:animated]; | |
[destViewController beginAppearanceTransition:NO animated:animated]; | |
// 2. viewのアニメーション | |
void (^before)() = ^{ | |
// any pre-animation process | |
}; | |
void (^block)() = ^{ | |
// animation block | |
destViewController.view.frame = destFinalFrame; | |
}; | |
void (^finish)() = ^{ | |
// 3. removeFromSuperview | |
[destViewController.view removeFromSuperview]; | |
// 4. endAppearanceTransition | |
[destViewController endAppearanceTransition]; | |
[srcViewController endAppearanceTransition]; | |
// 5. willMoveToParentViewController: | |
[destViewController willMoveToParentViewController:nil]; | |
// 6. removeFromParentViewController | |
[destViewController removeFromParentViewController]; | |
}; | |
if (animated) { | |
before(); | |
[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; | |
[UIView animateWithDuration:self.animationDuration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:block completion:^(BOOL finished) { | |
[[UIApplication sharedApplication] endIgnoringInteractionEvents]; | |
finish(); | |
}]; | |
} else { | |
before(); | |
block(); | |
finish(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment