1

I am working on an universal app both for iPad and iPhone devices that supports both landscape and portrait mode. In landscape it has more buttons in addition to what is there in portrait mode.

For iPhone, i was able to design different layouts using storyboard and it works as expected for wC|hC , wC|hR, wR|hC.

But in case of iPad, i could not design different layouts as size classes are same wR|hR for both landscape and portrait.

I referred solutions discussed @Sizing class for iPad portrait and Landscape Modes , iPad Landscape and Portrait different layouts with Size Class & tried to use code below:

override func overrideTraitCollectionForChildViewController(childViewController: UIViewController) -> UITraitCollection? {
    if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad &&
        view.bounds.width > view.bounds.height {

        let collections = [UITraitCollection(horizontalSizeClass: .Regular),
                           UITraitCollection(verticalSizeClass: .Compact)]
        return UITraitCollection(traitsFromCollections: collections)

    }
    return super.overrideTraitCollectionForChildViewController(childViewController)
}

But this code was never called. What should be the better way to achieve this ?

Will changing traits programmatically for iPad has any impact on app approval process as Apple itself provides same size class for iPad in Landscape & Portrait.

Community
  • 1
  • 1
CuriousDev
  • 301
  • 3
  • 16
  • Have you put this code in a 'parent' view controller that contains your actual 'child' view controller? – Paulw11 Oct 20 '16 at 22:43
  • @Paulw11Actually i have single view controller /container holding up many buttons and labels inside. I have not specifically created parent and child views. – CuriousDev Oct 20 '16 at 23:26
  • Right. That is the problem. I have no idea why Apple decided that iPads should have the same traits in both orientations, it seems that it totally defeats the purpose of traits. Anyway, what you need to do is create a UIViewController that has a container view full screen and put your *actual* view controller in this container. Put the code above in the containing view controller so that it updates the traits of the *contained* child – Paulw11 Oct 20 '16 at 23:28

0 Answers0