[英]Custom presented UIViewController changing to fullscreen
I have a view controller presented using UIModalPresentationCustom
presentation style. 我有一个使用
UIModalPresentationCustom
演示风格呈现的视图控制器。 I use a custom UIViewControllerTransitioningDelegate
to present the view controller as a sidebar (so it slides in from the edge of the screen and does not occupy the full screen). 我使用自定义
UIViewControllerTransitioningDelegate
将视图控制器显示为侧边栏(因此它从屏幕边缘滑入并且不占据整个屏幕)。
However when I then present another view controller from this one using UIModalPresentationFullScreen
— and then dismiss the full screen view controller, my underlying custom presented controller is suddenly resized to occupy the full screen. 然而,当我然后使用
UIModalPresentationFullScreen
呈现另一个视图控制器 - 然后关闭全屏视图控制器时,我的基础自定义显示控制器突然调整大小以占据整个屏幕。 Does anyone know why this is the case? 有谁知道为什么会这样?
Edit: this is essentially my animateTransition
method for presenting the sidebar — I've stripped out most of the code to make it readable. 编辑:这实际上是我用于呈现侧边栏的
animateTransition
方法 - 我已经删除了大部分代码以使其可读。 Basically it gets the container from the transitionContext, adds and animates the destination view controller's view to the container. 基本上它从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
}
}
Edit 2: Doing a little more research, I notice that the frame of my custom presented view controller's view is being set when the view controller above it in the modal stack is dismissed. 编辑2:做一些研究,我注意到我的自定义呈现视图控制器的视图的框架正在设置当模态堆栈中它上面的视图控制器被解除时。 The following stack trace leads to the frame being set as full screen:
以下堆栈跟踪导致框架设置为全屏:
0 -[MyCustomPresentedViewControllerView setFrame:]
1 -[UIView(MPAdditions) setFrameOrigin:]
2 -[UIViewControllerAccessibility(SafeCategory) dismissViewControllerWithTransition:completion:]
3 -[UIViewController dismissViewControllerAnimated:completion:]
Changing the presentation style by assigning: 通过分配来更改演示文稿样式:
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
results in the modal presentation controller occupying a fraction of the screen, the same fraction as the original presented view controller of the UIPresentationController
. 导致模态呈现控制器占据屏幕的一小部分,与
UIPresentationController
的原始呈现视图控制器UIPresentationController
。
However, using 但是,使用
viewController.modalPresentationStyle = UIModalPresentationOverFullScreen
is better for this case, since his modal controller is full screen. 对于这种情况更好,因为他的模态控制器是全屏的。
Try to use: 尝试使用:
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
It helped me in iOS 8.1 它在iOS 8.1中帮助了我
I am experiencing the same issue. 我遇到了同样的问题。 I've tried debugging it using symbolic breakpoints and there seem to be some internal call on some kind of layout manager that does this.
我已经尝试使用符号断点调试它,似乎在某种布局管理器上有一些内部调用来执行此操作。
While I wasn't able to "solve" this (it seems to me like a bug in the SDK), I was able to come up with a workaround that fixes this . 虽然我无法“解决”这个问题(在我看来,这似乎是SDK中的一个错误),但我能够找到解决此问题的解决方法 。 Basically, you have to set the correct dimensions of the presented view at two opportune times.
基本上,您必须在两个适当的时间设置所呈现视图的正确尺寸。 Like this:
像这样:
In the view controller that was presented using your custom UIPresentationController, add this:
在使用自定义UIPresentationController呈现的视图控制器中,添加以下内容:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
dispatch_async(dispatch_get_main_queue(), ^{
self.view.frame = [self.presentationController frameOfPresentedViewInContainerView];
});
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.view.frame = [self.presentationController frameOfPresentedViewInContainerView];
}
And if you are wondering: yes, you do need it to do in two places. 如果你想知道:是的,你确实需要它在两个地方做。 Because weirdly enough, when I did it only in the viewDidAppear async block, it got broken (resized to fullscreen) once the animation finished.
因为奇怪的是,当我仅在viewDidAppear异步块中执行它时,一旦动画结束它就会被破坏(调整为全屏)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.