iOS - Autolayout not good for 3.5" screens

338 Views Asked by At

I added Auto Layout to my app and it works perfectly for 4", 4.7" and 5.5" screens. However, when I tested it on the 3.5" (iPhone 4S), it was messy. A lot of objects were on top of each others. What can I do ? Is there a way to exclude iPhone 4S when uploading the app to iTunes Connect ? Will my app be rejected if it doesnt work for the iPhone 4S since it still supports iOS 9 ? (Using Xcode 7 GM)

EDIT :

I made another storyboard called "iPhone35" for the 3.5 inch and added this code to application function in AppDelegate.swift , but it always opens the Main.storyboard, which is for 4-inch and above screen sizes even if i choose iPhone 4S simulator.

let theBounds  = UIScreen.mainScreen().bounds
    let heightDevice = theBounds.size.height

    if heightDevice == 480 {
        let wantedStoryboard = UIStoryboard(name: "iPhone35", bundle: nil)
        let vc = wantedStoryboard.instantiateViewControllerWithIdentifier("MainPage")
        let rootViewController = self.window!.rootViewController
        rootViewController?.presentViewController(vc, animated: false, completion: nil)

    } else {
        let wantedStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = wantedStoryboard.instantiateViewControllerWithIdentifier("MainPage")
        let rootViewController = self.window!.rootViewController
        rootViewController?.presentViewController(vc, animated: false, completion: nil)

    }

what should i do ?

1

There are 1 best solutions below

0
SergeH On BEST ANSWER

So what i did was adding this function to AppDelegate.swift

func grabStoryBoard() -> UIStoryboard {

    var storyboard: UIStoryboard
    let width = UIScreen.mainScreen().width

    if width == 480.0 {
        storyboard = UIStoryboard(name: "iPhone35", bundle: nil)
    } else {
        storyboard = UIStoryboard(name: "Main", bundle: nil)
    }

    return storyboard

}

and then adding these few lines inside the didFinishLaunchingWithOptions function

let storyboard: UIStoryboard = self.grabStoryBoard()
  self.window!.rootViewController = storyboard.instantiateInitialViewController() as UIViewController?
  self.window!.makeKeyAndVisible()

And i also clicked the " is Initial View Controller " on the first controller of my new Storyboard.

The reason why width == 480.0 because my app is set to Landscape only.