当前位置: 首页 > 知识库问答 >
问题:

视图控制器方向未按预期工作,我缺少什么?

水恩
2023-03-14

我的应用程序是横向模式,除了一个单独的VC。TopVC是横向的,但加载MyVC时应根据设备方向旋转。如果模式纵向(横向模式很好),加载MyVC按预期工作但返回TopVC不会正确显示。
这是我在AppD中尝试的代码

elegate.swift

var orientationLock = UIInterfaceOrientationMask.landscape
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {        
    return self.orientationLock
}

func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
    self.orientationLock = orientation
}

在MyVC中。swift

override func viewWillAppear(_ animated: Bool) {
    // change orientation
    if let delegate = UIApplication.shared.delegate as? AppDelegate {
        delegate.lockOrientation(.allButUpsideDown)
    }
}
override func viewWillDisappear(_ animated: Bool) {        
    if let delegate = UIApplication.shared.delegate as? AppDelegate {
        delegate.lockOrientation(.landscapeLeft)
    }
}

有人能帮我解决这个问题吗?问题是,如果从MyVC返回纵向模式,则返回到以纵向模式显示的TopVC。

共有1个答案

徐杰
2023-03-14

如果有人需要答案,试试这个。对我有用。

override func viewWillDisappear(_ animated: Bool) {        
    if let delegate = UIApplication.shared.delegate as? AppDelegate {
        delegate.lockOrientation(.landscape)
    }
    if !UIWindow.isLandscape {
        UIDevice.current.setValue(Int(UIInterfaceOrientation.landscapeLeft.rawValue), forKey: "orientation")
    }
}
 类似资料:
  • 我正在使用spring Roo并希望访问Controller类中的一个bean,该类在ApplicationContext.xml中具有以下配置: 配置类本身是: 在我的Controller中,我认为一个简单的Autowired注释应该可以完成这项工作 在启动过程中,spring在setSkipWeeks方法中打印消息。不幸的是,每当我在控制器中调用config.getSkipWeeks()时,它

  • 当我运行以下程序时,它只打印 然而,从Java 8的equalsIgnoreCase文档中我们发现: 如果以下至少一项为真,则两个字符c1和c2被视为相同的忽略情况: •对每个字符应用java.lang.character.ToUpperCase(char)方法会产生相同的结果 所以我的问题是为什么这个程序不打印 在这两种操作中,都使用了大写字符。

  • 我试图使用来传输我根据前面的问题设置的自定义标头。 我在文件中读到... 我的属性包括:

  • 我正在和selenium一起工作,刮一些数据。 有一个按钮在页面上,我正在点击说“Custom_Cols”。这个按钮为我打开了一个窗口,我可以在那里选择我的列。 我的问题是为什么新窗口上的元素不可见,即使我正在等待元素的可见。补充一下,我已经尝试增加延迟时间,但我还是会偶尔出现这个错误。 我的密码在这里

  • 根据以下文档:http://testng.org/doc/documentation-main.html “如果测试类上有一个方法tearDown(),那么在每个测试方法之前和之后都会调用它”(JUnit 3) 我使用的是JUnit版本:3.8.1 这里的这个是在我的测试之前运行的,但我希望它会在测试之后。它在测试后没有运行: 我可以通过将第一行更改为: 但是,下一个类(下面)的表示法与第一个类完