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
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ typedef void (^RZSingleChildContainerViewControllerCompletionBlock)(void);
- (UIView *)childContentContainerView;

@end



Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ @interface RZSingleChildContainerAlphaTransitioner : NSObject <UIViewControllerA

@end


// -------

@interface RZSingleChildContainerViewController ()
Expand All @@ -55,6 +56,8 @@ @interface RZSingleChildContainerViewController ()

@property (weak, nonatomic) UIViewController *viewControllerOnWhichWeCalledBegin;

@property (copy, nonatomic) void(^queuedPresentationBlock)();

@end

@implementation RZSingleChildContainerViewController
Expand Down Expand Up @@ -163,41 +166,50 @@ - (void)setContentViewController:(UIViewController *)viewController animated:(BO

- (void)setContentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(RZSingleChildContainerViewControllerCompletionBlock)completion
{
__weak __typeof(self) weakSelf = self
;
if ( self.isTransitioning ) {
[NSException raise:NSInternalInconsistencyException format:@"%@: Cannot start a transition while a transition is already in place.", [self class]];

self.queuedPresentationBlock = ^{
[weakSelf setContentViewController:viewController animated:animated completion:completion];
};

return;
}

__weak __typeof(self) wself = self;


// We need to set isTransitioning to NO once the transition completes.
// Then we run the passed-in completion block if it is not nil.
void (^compoundCompletion)(void) = ^{
self.isTransitioning = NO;
if ( completion ) {
completion();
}
if ( self.queuedPresentationBlock != nil ) {
self.queuedPresentationBlock();
self.queuedPresentationBlock = nil;
}
};

[self performBlockWhenViewLoaded:^{
self.isTransitioning = YES;
UIViewController *currentChild = wself.currentContentViewController;
UIViewController *currentChild = weakSelf.currentContentViewController;

if ( animated ) {

[currentChild beginAppearanceTransition:NO animated:YES];

[currentChild willMoveToParentViewController:nil];
[wself addChildViewController:viewController];
viewController.view.frame = [wself childContentContainerView].bounds;
[weakSelf addChildViewController:viewController];
viewController.view.frame = [weakSelf childContentContainerView].bounds;
viewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[viewController beginAppearanceTransition:YES animated:YES];

RZSingleChildContainerTransitionContext *ctx = [[RZSingleChildContainerTransitionContext alloc] initWithContainerVC:wself
RZSingleChildContainerTransitionContext *ctx = [[RZSingleChildContainerTransitionContext alloc] initWithContainerVC:weakSelf
fromVC:currentChild
toVC:viewController
completion:compoundCompletion];
[wself.contentVCAnimatedTransition animateTransition:ctx];
[weakSelf.contentVCAnimatedTransition animateTransition:ctx];
}
else {

Expand All @@ -210,14 +222,14 @@ - (void)setContentViewController:(UIViewController *)viewController animated:(BO
[currentChild removeFromParentViewController];
[currentChild endAppearanceTransition];

[wself addChildViewController:viewController];
viewController.view.frame = [wself childContentContainerView].bounds;
[weakSelf addChildViewController:viewController];
viewController.view.frame = [weakSelf childContentContainerView].bounds;
viewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
if ( hasWindow ) {
[viewController beginAppearanceTransition:YES animated:NO];
}
[[wself childContentContainerView] addSubview:viewController.view];
[viewController didMoveToParentViewController:wself];
[[weakSelf childContentContainerView] addSubview:viewController.view];
[viewController didMoveToParentViewController:weakSelf];
if ( hasWindow ) {
[viewController endAppearanceTransition];
}
Expand Down
Loading