gpt4 book ai didi

swift - 在 Swift 中添加 NavigationBar 和 NavigationController 后不应该调用 autorotate

转载 作者:行者123 更新时间:2023-11-30 10:17:43 24 4
gpt4 key购买 nike

我现在正在绞尽脑汁试图解决我认为是一个简单的函数。我正在使用 Xcode 6.2 为带有 3 个 View Controller 的 iPad 创建 iOS 8 应用程序。我的目标是应用程序启动后,它将所有 View 锁定在横向方向。如果它关闭并在另一个横向方向重新打开,则所有 View 都会使用它。我确实使用下面的代码实现了这一点,但必须添加一个导航 Controller ,因为我需要一个导航栏,而且它现在总是旋转。我发现一些信息表明这可能是iOS8的一个错误。我尝试过的建议并没有解决问题,因为它们是 Object-C,这很有趣,但因为它不是快速的,所以我迷失了。

iOS 6 shouldAutorotate: is NOT being called

是否有一种简单的方法可以通过强制导航 Controller 停止旋转来实现此目的?这是一个曾经有效的代码片段,锁屏代码位于每个 VC 中:-

        // Get orintation of screen if 'true' Home button on RIGHT
if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft) {
Oriention_Number = HomeButtonRight
Screen_Orient_Vert = -1
Screen_Orient_Horiz = 1
} else {
Oriention_Number = HomeButtonLeft
Screen_Orient_Vert = 1
Screen_Orient_Horiz = -1
}
preferences.setInteger(Oriention_Number, forKey: "Oriention_Number_Prefs")


// Lock Screen
override func shouldAutorotate() -> Bool {
return false
}

override func supportedInterfaceOrientations() -> Int {
return Oriention_Number // Landscape HomeButtonLeft = 16 HomeButtonRight = 8
}

最佳答案

By UINavigationController 不会将 shouldAutorotate 调用传递给其子级。为 UINavigationController 添加一个类别(或其子类),并实现以下内容:

- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}

这将使用您现有的 shouldAutorotate 逻辑。

关于swift - 在 Swift 中添加 NavigationBar 和 NavigationController 后不应该调用 autorotate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29329420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com