【问题标题】:IOS 7: Transparent Viewcontroller Background over another Viewcontroller with different Orientation behaviourIOS 7:具有不同方向行为的另一个 Viewcontroller 上的透明 Viewcontroller 背景
【发布时间】:2014-08-12 10:54:20
【问题描述】:

我有 2 个 ViewController (IOS7),我想用透明背景和不同的方向行为将第二个显示在第一个之上。

例如:按下第一个 ViewController 上的按钮将调出第二个 ViewController,但第一个仍会在第二个 ViewController 的透明区域的背景上可见。 如果我旋转手机,只有第二个 ViewController 会旋转,而第一个(背景中的那个)保持相同的方向。

有什么建议吗? 谢谢!

【问题讨论】:

  • 在您的属性检查器上将 alpha 设置为 -1

标签: ios iphone ios7 uiviewcontroller transparent


【解决方案1】:

您可以在第一个视图控制器上以模态方式呈现第二个视图控制器,第一个视图控制器的 modalPresentationStyle 类型为 UIModalPresentationCurrentContext

如果您的第一个 ViewController 嵌入在 UINavigationController 之类的 ContainerViewController 中,则必须在该容器上设置 modalPresentationStyle 并需要在其上显示第二个 ViewController。

在您的第一个 ViewController 中,它看起来像:

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

当然,您还必须为支持的界面方向配置/实现所需的行为。例如,通过在第二个 ViewController 中覆盖 supportedInterfaceOrientations(),如下所示:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

【讨论】:

  • 成功了!!!非常感谢您的帮助!!!!!关键是使用 UIModalPresentationCurrentContext 作为presentationStyle =D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-13
相关资源
最近更新 更多