为运行iPad的iPhone应用程序定义宽高比

时间:2018-05-15 06:42:02

标签: ios iphone xcode ipad iphone-4

我的应用程序仅限iPhone,并针对运行iOS 11的所有设备进行了优化...因此不包括iPhone4 Screen-Sizes。 现在我也不支持iPad,现在如果你在那里运行我的应用程序,它将是扩展的iPhone版本。问题是iPad选择了iPhone 4 Aspect-Ratio ......

有没有一种简单的方法可以告诉iOS不要这样做?

1 个答案:

答案 0 :(得分:0)

据我所知,遗憾的是你无法做到这一点。
我修复它的方式(我的问题是屏幕没有制作如此小的尺寸。因此,布局看起来很糟糕)使用AssistantKit来确定设备类型:

    let device = Device.type

        switch device {
        case .phone:      print("iPhone")
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "iphoneVC") as! LoginViewController
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()

        case .pad:        print("iPad");
            let storyboard = UIStoryboard(name: "iPad", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "ipadVC") as! LoginViewController
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()

        case .pod:        print("iPod")
            let storyboard = UIStoryboard(name: "iPad", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "ipadVC") as! LoginViewController
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()

        case .simulator:  print("Simulator")
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "iphoneVC") as! LoginViewController

// this is used to test in the Sim, this kit can't determine device type from the Sim        
//            let storyboard = UIStoryboard(name: "iPad", bundle: nil)
//            let vc = storyboard.instantiateViewController(withIdentifier: "ipadVC") as! LoginViewController
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()
        default:          print("Unknown")
        }

如果您只想专门检查特定的设备类型(使用SIM卡):

Device.isPhone     // true for iPhones even if it's Simulator
Device.isPhoneX    // true for iPhoneX even if it's Simulator
Device.isPad       // true for iPads even if it's Simulator
Device.isPadPro    // true for iPad Pros even if it's Simulator
Device.isPod       // true for iPods
Device.isSimulator // true for Simulators

您还可以使用此工具包根据屏幕大小或特定设备切换故事板/视图: 屏幕尺寸:

let screen = Device.screen

switch screen {
case .inches_3_5:  print("3.5 inches")
case .inches_4_0:  print("4.0 inches")
case .inches_4_7:  print("4.7 inches")
case .inches_5_5:  print("5.5 inches")
case .inches_7_9:  print("7.9 inches")
case .inches_9_7:  print("9.7 inches")
case .inches_12_9: print("12.9 inches")
default:           print("Other display")
}

设备版本:

let version = Device.version

switch version {
case .phone4:       print("iPhone 4")
case .phone4S:      print("iPhone 4S")
case .phone5:       print("iPhone 5")
case .phone5C:      print("iPhone 5C")
case .phone5S:      print("iPhone 5S")
case .phone6:       print("iPhone 6")
case .phone6S:      print("iPhone 6S")
case .phone6Plus:   print("iPhone 6 Plus")
case .phone6SPlus:  print("iPhone 6 S Plus")

case .pad1:         print("iPad 1")
case .pad2:         print("iPad 2")
case .pad3:         print("iPad 3")
case .pad4:         print("iPad 4")
case .padAir:       print("iPad Air")
case .padAir2:      print("iPad Air 2")
case .padMini:      print("iPad Mini")
case .padMini2:     print("iPad Mini 2")
case .padMini3:     print("iPad Mini 3")
case .padMini4:     print("iPad Mini 4")
case .padPro:       print("iPad Pro")

case .podTouch1:    print("iPod 1")
case .podTouch2:    print("iPod 2")
case .podTouch3:    print("iPod 3")
case .podTouch4:    print("iPod 4")
case .podTouch5:    print("iPod 5")
case .podTouch6:    print("iPod 6")

case .simulator:    print("Simulator")

default:            print("Unknown device")
}

来源:AssistantKit