![](/img/trans.png)
[英]How to get the name of the UIViewController that presented the custom AlertView?
[英]Custom presented UIViewController changing to fullscreen
我有一个使用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:]
通过分配来更改演示文稿样式:
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
导致模态呈现控制器占据屏幕的一小部分,与UIPresentationController
的原始呈现视图控制器UIPresentationController
。
但是,使用
viewController.modalPresentationStyle = UIModalPresentationOverFullScreen
对于这种情况更好,因为他的模态控制器是全屏的。
尝试使用:
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
它在iOS 8.1中帮助了我
我遇到了同样的问题。 我已经尝试使用符号断点调试它,似乎在某种布局管理器上有一些内部调用来执行此操作。
虽然我无法“解决”这个问题(在我看来,这似乎是SDK中的一个错误),但我能够找到解决此问题的解决方法 。 基本上,您必须在两个适当的时间设置所呈现视图的正确尺寸。 像这样:
在使用自定义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];
}
如果你想知道:是的,你确实需要它在两个地方做。 因为奇怪的是,当我仅在viewDidAppear异步块中执行它时,一旦动画结束它就会被破坏(调整为全屏)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.