/*
This method can be used to transition between sibling child view controllers.
The receiver of this method is their common parent view controller. (Use [UIViewController
addChildViewController:] to create the parent/child relationship.) This method will add the toViewController's view to the superview of the fromViewController's view and the fromViewController's view will be removed from its superview after the transition completes. It is important to allow this method to add and remove the views. The arguments to this method are the same as those defined by UIView's block animation API. This method will fail with an NSInvalidArgumentException if the parent view controllers are not the same as the receiver, or if the receiver explicitly forwards its appearance and rotation callbacks to its children. Finally, the receiver should not be a subclass of an iOS container view controller. Note also that it
is possible to use the UIView APIs directly. If they are used it is important to ensure that the
toViewController's view is added to the visible view hierarchy while the fromViewController's view is removed.
*/
- (void)transitionFromViewController:(UIViewController*)fromViewController toViewController:(UIViewController*)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void(^__nullable)(void))animations
completion:(void(^__nullable)(BOOLfinished))completionNS_AVAILABLE_IOS(5_0);
/**
*切换控制器
*
* @param oldController旧控制器
* @param newController新控制器
*/
- (void)replaceController:(QDFViewController*)oldController newController:(QDFViewController*)newController
{
/**
*着重介绍一下它
*
transitionFromViewController:toViewController:duration:options:animations:completion:
* fromViewController当前显示在父视图控制器中的子视图控制器
* toViewController将要显示的姿势图控制器
* duration动画时间(这个属性,old
friend了O(∩_∩)O)
* options动画效果(渐变,从下往上等等,具体查看API)
* animations转换过程中得动画
* completion转换完成
*/
if(newController == oldController) {
return;
}
oldController.visible=NO;
newController.visible=YES;
[self addChildViewController:newController];
if(!oldController) {
[self.rightPlaceholderView addSubview:newController.view];
self.currentVC = newController;
}
else{
[self transitionFromViewController:oldController toViewController:newController duration:0.0 options:0 animations:nil completion:nil];
[newController didMoveToParentViewController:self];
[oldController willMoveToParentViewController:nil];
[oldController removeFromParentViewController];
self.currentVC = newController;
}
[newController.view mas_makeConstraints:^(MASConstraintMaker*make) {
make.edges.equalTo(self.rightPlaceholderView);
}];
}