简体   繁体   English

iOS 7:透明的Viewcontroller背景在另一个具有不同方向行为的Viewcontroller上

[英]IOS 7: Transparent Viewcontroller Background over another Viewcontroller with different Orientation behaviour

I have 2 ViewControllers (IOS7) and I want to show the second one over the first one with a transparent background and different orientation behaviour. 我有2个ViewController(IOS7),我想显示第一个而不是第一个,具有透明的背景和不同的方向行为。

For Example: Pressing a button on the first ViewController will bring up the second ViewController but the first one will still be visible on the background in the transparent areas of the second ViewController. 例如:按下第一个ViewController上的按钮将调出第二个ViewController,但是第一个在背景上仍将在第二个ViewController的透明区域中可见。 If I rotate the phone only the second ViewController will rotate while the first one (the one in the background) stays in the same orientation. 如果旋转手机,则只有第二个ViewController旋转,而第一个(背景中的一个)保持相同方向。

Any suggestions? 有什么建议么? Thanks! 谢谢!

You can present the second ViewController modally on the first on, with the first one having a modalPresentationStyle of type UIModalPresentationCurrentContext . 您可以在第一个上以模态形式显示第二个ViewController,第一个具有UIModalPresentationCurrentContext类型的modalPresentationStyle

If your first ViewController is embedded in a ContainerViewController like UINavigationController, you have to set the modalPresentationStyle on that one and need to present the second ViewController on it. 如果您的第一个ViewController嵌入在UINavigationController之类的ContainerViewController中,则必须在该容器上设置modalPresentationStyle,并需要在其上显示第二个ViewController。

In your first ViewController, it would look like: 在您的第一个ViewController中,它看起来像:

- (void)buttonTapped:(id)sender {
    self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self.navigationController presentViewController:[SecondViewController new] animated:YES completion:nil];
}

You also have to configure/implement your desired behavior for the supported interface orientations, of course. 当然,您还必须为支持的界面方向配置/实现所需的行为。 For example by overriding supportedInterfaceOrientations() in the second ViewController, like so: 例如,通过重写第二个ViewController中的supportedInterfaceOrientations() ,如下所示:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM