这是意料之中的,因为全屏演示不会恢复由frameOfPresentedViewInContainerView
. 解决此问题的推荐方法是创建一个包装视图,您将在其中插入呈现的视图控制器的视图。这是您的自定义演示控制器的相关代码:
- (void)presentationTransitionWillBegin {
// wrapper is a property defined in the custom presentation controller.
self.wrapper = [UIView new];
[self.wrapper addSubview:self.presentedViewController.view];
}
- (CGRect)frameOfPresentedViewInContainerView {
CGRect result = self.containerView.frame;
// In this example we are doing a half-modal presentation
CGFloat height = result.size.height/2;
result.origin.y = height;
result.size.height = height;
return result;
}
- (UIView *)presentedView {
return self.wrapper;
}
- (BOOL)shouldPresentInFullscreen {
return NO;
}
- (void)containerViewWillLayoutSubviews {
self.wrapper.frame = self.containerView.frame;
self.presentedViewController.view.frame = [self frameOfPresentedViewInContainerView];
}
请注意,我们重写presentedView
以返回包装视图而不是默认值 - 呈现的视图控制器的视图。这样,即使第二个呈现修改了包装器的框架,呈现的视图控制器的视图也不会改变。