我正在编写自定义UIStoryboardSegue
来为视图之间的转换设置动画。触发segue时,会要求每个控制器(源和目标)进行相应的动画处理。以下是:
- (void)perform
{
UIViewController * sourceViewController = [self sourceViewController];
UIViewController * destinationViewController = [self destinationViewController];
UIViewController * containerViewController = [self containerViewController];
UIView * sourceView = sourceViewController.view;
UIView * destinationView = destinationViewController.view;
UIView * containerView = containerViewController.view;
// The container view is as large as the union of the two other views
CGRect sourceFrame = sourceView.frame;
CGRect destinationFrame = destinationView.frame;
CGRect containerFrame = CGRectUnion(sourceFrame, destinationFrame);
[containerView setFrame:containerFrame];
// The two views are presented in a container view; this way no one fights about who gets what
[sourceView removeFromSuperview];
[containerView addSubview:sourceView];
[containerView addSubview:destinationView];
// [sourceViewController presentViewController:containerViewController animated:NO completion:^{
// NSLog(@"done presenting");
// }];
// NSLog(@"done calling presenting");
id <HyTransition> presentingTransition = [self presentingTransitionForViewController:destinationViewController];
id <HyTransition> dismissingTransition = [self dismissingTransitionForViewController:sourceViewController];
// Perform the transitions
[presentingTransition performWithTransitionContext:self.presentingContext];
[dismissingTransition performWithTransitionContext:self.dismissingContext];
}
问题在于展示包含视图。如果源视图控制器是标准视图控制器,它可以很好地工作,但如果它是UINavigationController
或其他类型的控制器,它们不会将它们的视图添加到视图层次结构中。这样做,我明白了:
Warning: Attempt to present <HyPresentationViewController: 0x7fdac2d34b60> on <HyRootController: 0x7fdac2e28590> whose view is not in the window hierarchy!
如何呈现包含视图?
编辑:请注意,我不需要包含视图控制器 - 包含视图就足够了。