Define aspect ratio for iPhone app running iPad

453 views Asked by At

My App is iPhone only and is optimized for all Devices running iOS 11... so that does not include iPhone4 Screen-Sizes. Now I also don't support the iPad and now if you run my app there, it will be the iPhone version scaled up. The problem is that the iPad chooses the iPhone 4 Aspect-Ratio...

Is there a simple way to tell iOS not to do that?

1

There are 1 answers

0
Egghead On

As far as I know, you can't do that, unfortunately.
The way I fixed it (my problem was that the screens weren't made for such a small size. so, the layout looked terrible) was using AssistantKit to determine the device type:

    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")
        }

if You only want to specifically check for a specific device type (works with 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

You could also use this Kit to switch storyboard/views based on screen size or specific device: Screen size:

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")
}

Device version:

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")
}

Source: AssistantKit