Search code examples
swiftios8xcode6.1

Formsheet ios 8 constraints are same as iphones constraints


I have this problem where formsheet in ios 8 is taking the constraints set for "compact - width regular -height" (that is all iPhones constraints) instead of "any- any" or "regular -width regular -height". I have two different design for iPhone and iPad since the formsheet is consuming iPhones constraint iam not able to achieve the same. Any help on this would be aprreciatd


Solution

  • From the UIViewController class reference:

    In a horizontally regular environment, a presentation style that displays the content centered in the screen. The width and height of the content area are smaller than the screen size and a dimming view is placed underneath the content. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.

    In a horizontally compact environment, this option behaves the same as UIModalPresentationFullScreen.

    Because the form sheet presentation on iPad is compact width and regular height, these are the values you'll get when you present a form sheet.


    If you don't want the default size classes you can override them.

    If your view controller is a child view controller of another, you can use setOverrideTraitCollection(_:forChildViewController:) and override the size class constraints for the child controller.

    If your view controller is NOT a child view controller, you're not really supposed to change the trait collection, but you can do it using this hack.


    The best solution would be to design your view controller to look appropriate in the default (correct) size constraints applied for a form sheet view controller presentation. You can usually do this by avoiding setting width constraints and only setting leading and trailing constraints.