草庐IT

ios - supportedInterfaceOrientations 在除 6+ 以外的所有 iPhone 上调用

coder 2023-09-05 原文

在我的 iPhone 应用程序上,我将它限制为仅在项目目标部署信息下的纵向

有一个页面我只想要横向的,我使用 supportedInterfaceOrientations 方法来获得它。

标准实现:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Landscape
    }

除 iPhone 6+ 外,它在所有 iPhone 设备和 iOS 版本上都能完美运行。永远不会调用 supportedInterfaceOrientations 方法。

我找不到任何可能只影响 iPhone 6+ 的原因,如有任何提示,我们将不胜感激。

最佳答案

你可以试试这个对我有用的代码

// you have to import foundation
import Foundation

class YourViewController : UIViewController {
    var device = self.platform()

     override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)

     if device.lowercaseString.rangeOfString("iphone6plus") != nil {
     supportedInterfaceOrientations()
    }

    }

    // add this method to your view controller
    func platform() -> String {
            var sysinfo = utsname()
            uname(&sysinfo) // ignore return value
            return NSString(bytes: &sysinfo.machine, length: Int(_SYS_NAMELEN), encoding:
                NSASCIIStringEncoding)! as String
        }

请注意,这不会在模拟器上运行,但会在实际设备上完美运行。

关于ios - supportedInterfaceOrientations 在除 6+ 以外的所有 iPhone 上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32899061/

有关ios - supportedInterfaceOrientations 在除 6+ 以外的所有 iPhone 上调用的更多相关文章

随机推荐