我有一个使用UIModalPresentationCustom
演示样式呈现的视图控制器。我使用自定义UIViewControllerTransitioningDelegate
将视图控制器呈现为侧边栏(因此它从屏幕边缘滑入并且不占据整个屏幕)。
UIModalPresentationFullScreen
但是,当我使用- 然后关闭全屏视图控制器时,当我从这个视图控制器呈现另一个视图控制器时,我的底层自定义呈现控制器突然调整大小以占据全屏。有谁知道为什么会这样?
编辑:这本质上是我animateTransition
展示侧边栏的方法——我已经删除了大部分代码以使其可读。基本上,它从transitionContext 获取容器,将目标视图控制器的视图添加到容器中并为其设置动画。
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIView *container = transitionContext.containerView;
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *fromView = fromVC.view;
UIView *toView = toVC.view;
if( toVC.isBeingPresented )
{
[container addSubview:toView];
//... Animate some new frame for toView
//Call [transitionContext completeTransition:YES] on animation completion
}
else
{
//... Animate fromView out
//On completion remove fromView from superview
//Call [transitionContext completeTransition:YES] on animation completion
}
}
编辑2:做更多的研究,我注意到当模式堆栈中它上面的视图控制器被解除时,我的自定义呈现视图控制器的视图的框架正在设置。以下堆栈跟踪导致框架被设置为全屏:
0 -[MyCustomPresentedViewControllerView setFrame:]
1 -[UIView(MPAdditions) setFrameOrigin:]
2 -[UIViewControllerAccessibility(SafeCategory) dismissViewControllerWithTransition:completion:]
3 -[UIViewController dismissViewControllerAnimated:completion:]