我有一个自定义容器,它删除了视图控制器并在滑动动画上添加了新的viewcontroller,我从某个地方获得了这个参考函数,但是在这个函数动画中首先删除当前的viewcontroller,即在完成滑动动画后删除完成后的curr viewcontoller它的幻灯片在新的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;
}];
}];
}
我希望它像UIpageviewcontroller一样同时发生,它应该一起发生curr viewcontroller的slideOut和新viewcontroller的SlideIn我将如何在这种情况下执行此操作