I ma working on some layout logic that needs to know what the width would be of the view if the app got in compact size class mode while on iPad. So, lets say the app is running full screen on iPad, and I am in the view controller, then the view.traitCollection.horizontalSizeClass
would be regular
. While in that mode, I would like to calculate what the width of the view would be if the app were to be in compact mode.
Is there a way to calculate that without being in compact mode first?
What you are looking for is not possible, there is an alternate way to achieve it. I am not sure it will fulfill your requirement. You can use the following callback method to identify destination size. This method will be called in other cases too when it changing size without changing trait collection.
viewWillTransitionToSize:withTransitionCoordinator:
Ideally, you should not depend on size, it will vary from device to device it will introduce more issues when new screen size device is introduced.
Apple documentation:https://developer.apple.com/documentation/uikit/uicontentcontainer/1621466-viewwilltransitiontosize