I have a custom container which removes view controller and adds new viewcontroller on swipe animation , I have got this reference function from somewhere which does the same thing but in this function animation removes the current viewcontroller first i.e. after completing slideout animation to remove the curr viewcontoller after it gets complete it's slideIn the new viewcontroller
- (void)swapCurrentControllerWith:(UIViewController*)viewController
eContainerTransitionType:(enum eContainerTransitionType )eContainerTransitionType
{
float animDuration = 0.0f;
float yTrans = 0.0f;
CGPoint point = CGPointMake(0, 0);
[self setupBeforeTransition];
switch (eContainerTransitionType) {
case E_CONTAINER_TRANSITION_NONE:
animDuration = 0.0f;
point = CGPointMake(0, 0);
break;
case E_CONTAINER_TRANSITION_LEFT:
animDuration = 0.5f;
point = CGPointMake(2000, 0);
break;
case E_CONTAINER_TRANSITION_RIGHT:
animDuration = 0.5f;
point = CGPointMake(-2000, 0);
break;
case E_CONTAINER_TRANSITION_UP:
animDuration = 0.5f;
point = CGPointMake(0, 2000);
break;
case E_CONTAINER_TRANSITION_DOWN:
animDuration = 0.5f;
point = CGPointMake(0, -2000);
break;
default:
break;
}
//1. The current controller is going to be removed
[self.currentDetailViewController willMoveToParentViewController:nil];
//2. The new controller is a new child of the container
[self addChildViewController:viewController];
//3. Setup the new controller's frame depending on the animation you want to obtain
viewController.view.frame = CGRectMake(point.x, point.y, viewController.view.frame.size.width, viewController.view.frame.size.height);
//3b. Attach the new view to the views hierarchy
[self.containerView addSubview:viewController.view];
//Save the button position...we'll use it later
// CGPoint buttonCenter = self.button.center;
[UIView animateWithDuration:1.3
//4. Animate the views to create a transition effect
animations:^{
//The new controller's view is going to take the position of the current controller's view
viewController.view.frame = self.currentDetailViewController.view.frame;
//The current controller's view will be moved outside the window
self.currentDetailViewController.view.frame = CGRectMake(-point.x,
-point.y,
self.currentDetailViewController.view.frame.size.width,
self.currentDetailViewController.view.frame.size.height);
//...and the same is for the button
// self.button.center = CGPointMake(buttonCenter.x, 1000);
}
//5. At the end of the animations we remove the previous view and update the hierarchy.
completion:^(BOOL finished) {
//Remove the old Detail Controller view from superview
[self.currentDetailViewController.view removeFromSuperview];
//Remove the old Detail controller from the hierarchy
[self.currentDetailViewController removeFromParentViewController];
//Set the new view controller as current
self.currentDetailViewController = viewController;
[self.currentDetailViewController didMoveToParentViewController:self];
[self setupAfterTransition];
//reset the button position
[UIView animateWithDuration:0.5 animations:^{
// self.button.center = buttonCenter;
}];
}];
}
I want it to happen simultaneously like UIpageviewcontroller sort of , It should happen together slideOut of curr viewcontroller and SlideIn of new viewcontroller how will I do this in this scenario