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
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- UIPanGestureRecognizer is not working in iOS 13
- What does a Firebase observer actually do?
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
From the UIViewController class reference:
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.
I found a different way to solve this for presented view controllers, such as form sheets which are not child view controllers.
I override
viewWillLayoutSubviews
and then layout based on the presenting view controller's trait collection.Where
updateLayout(forSizeClass:)
is our function which does whatever we need to do to support the trait environment.The benefit of this approach is that we are not explicitly checking the device type (
.pad
or.phone
) and we are not explicitly thresholding the view size (which may change in the future). This approach natively supports iPad split view, allowing your layout to fallback to an iPhone style layout when the presenting view controller hits a.compact
size class.The primary assumption here is that your presenting view controller is full screen. But for form sheets this is often the case.