带有Transition的UIModalPresentationCurrentContext?

Jos*_*ane 10 iphone objective-c ipad uimodaltransitionstyle uimodalpresentationstyle

我试图模态呈现如下的视图控制器:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"addPopover"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:YES];
Run Code Online (Sandbox Code Playgroud)

现在使用UIModalPresentationCurrentContext手段我可以使用透明背景显示此视图,并查看新视图背后的另一个视图.然而,它阻止我能够通过转换呈现它.

有什么想法吗?或者我如何解决这个问题?谢谢.

Mr.*_*. T 25

我能够通过设置modalPresentationStyle = UIModalPresentationCurrentContext我的UIWindow的rootViewController 来实现这一点,如果我没有在这个rootViewController之上提供任何新的全屏viewControllers.我做了这样的事情:

UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用UINavigationController作为我的窗口的rootViewController和各种其他自定义视图控制器.只要窗口的rootViewController知道发生了什么,任何子视图控制器都可以调用presentViewController:animated:completion:而不会使基础视图变黑.

但是,假设您在窗口的rootViewController上显示另一个viewController.这个新的viewController被呈现modalPresentationStyle = UIModalPresentationFullScreen(即占据屏幕),然后你必须调用modalPresentationStyle = UIModalPresentationCurrentContext最顶层的viewController.

所以回顾一下:

  • 如果您有UINavigationController - > UIViewController(它们可以被推入和弹出),那么您可以modalPresentationStyle = UIModalPresentationCurrentContext在UINavigationController上进行设置.
  • 如果您有UINavigationController - > UIViewController - > new-UIViewController(将modalPresentationStyle设置为UIModalPresentationFullScreen),那么您可以设置modalPresentationStyle = UIModalPresentationCurrentContextnew-UIViewController.

希望这也适合你们!


Mic*_*han 11

全屏模式不允许您看到底层.很烦我知道.

从您的代码中我假设"addPopover"实际上是一个全屏视图,其中您将内容作为子部分,而其余部分是透明的.

试试这个:

vc.modalPresentationStyle = UIModalPresentationCurrentContext;
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:vc animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)

注意:我建议添加一个低alpha背景颜色,让用户知道当你弹出顶部时他们无法与视图的其余部分进行交互...

  • 是的,在我的项目中,两个ViewControllers都是相同的大小.我尝试了你的代码,没有任何变化.属性设置`modalPresentationStyle = UIModalPresentationCurrentContext`需要在这里应用于self,而不是vc.我想我将不得不开始我自己的问题,而不是在这个问题上提供赏金,因为这里没有解决方案,即使它被标记为一个. (2认同)