iOS swift 标签栏的奇怪行为

标签 ios swift uitabbarcontroller

我的应用程序仅处于纵向模式,但一些 View Controller (用于阅读 pdf)可以选择处于横向模式。 我正在使用此功能来允许横向模式

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) {
    if (rootViewController.responds(to: Selector(("canRotate")))) {
// Unlock landscape view orientations for this view controller
return .allButUpsideDown;
}
}
// Only allow portrait (standard behaviour)
return .portrait;
}

然后在横向模式下,如果我们按后退按钮,我会使用此功能强制之前的 View Controller 返回纵向模式

override func viewWillDisappear(_ animated : Bool) {
    super.viewWillDisappear(animated)

    if (self.isMovingFromParentViewController) {
        UIDevice.current.setValue(Int(UIInterfaceOrientation.portrait.rawValue), forKey: "orientation")
    }
}

它在 iPhone(plus)上运行良好,上一页返回到纵向模式,标签栏也很好,但有一个错误,仅出现在 iPhone no plus(分辨率较小)上,上一页返回在纵向模式下,但选项卡栏出现故障。

picture

有人有想法吗?我不知道发生了什么..

最佳答案

我通过删除“解决”了该问题

override func viewWillDisappear(_ animated : Bool) {
super.viewWillDisappear(animated)

if (self.isMovingFromParentViewController) {
    UIDevice.current.setValue(Int(UIInterfaceOrientation.portrait.rawValue), forKey: "orientation")
}

在 subview 中

并将其添加到父 View 中。

override func viewDidAppear(_ animated: Bool) {
    UIDevice.current.setValue(Int(UIInterfaceOrientation.portrait.rawValue), forKey: "orientation")
}

我仍然不明白这个错误,但至少有一个解决方法......

请注意,如果我将此代码放入 viewWillAppear 中,我会遇到相同的错误

关于iOS swift 标签栏的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52996223/

相关文章:

ios - 上传 iOS 时的 SPI 检查是什么?

xcode - 如何在 Mac OS 中创建模态滑出窗口?

ios - 如何在 Dismiss 后以编程方式更改 UITabBar 选定的索引?

iphone - 使用 Storyboard在两个 Controller 之间传递数据

ios - 为什么 NSArray 的对象在 ARC 模式下不调用 dealloc 方法?

android - Phonegap/Cordova - 构建 Apk

iphone - 如何知道 StatusBar 大小何时发生变化 (iPhone)

ios - 在 SwiftUI View 中设置高度的问题

swift - 通过偏移量获取元素到序列中

ios - 通过 Storyboard的 UITabBar 图像