I’ve an app whose fundamental view controller (name it VC-A) is locked in portrait orientation. I wish to current a sheet-style modal (name it VC-B) over high of it, permitting the modal to rotate freely. There are some extra constraints:
- VC-A ought to stay in portrait orientation always. No glimpses of or animations involving panorama orientation, even when transitioning to or from VC-B.
- If VC-B is offered whereas the gadget is in a panorama orientation, it ought to current in that orientation (slide in from the lengthy aspect of the display screen). It must also dismiss on this course.
- In portrait orientation, VC-B ought to current with the default transition/animation such that VC-A is pushed down and scaled barely.
There have been many comparable questions and responses over time, however many of the instructed solutions do not meet all of those necessities, do not work with modal presentation, or are a lot too hacky. That mentioned, this could positively be potential – I’ve seen a minimum of two apps with implementations that meet my necessities. Undecided if it is kosher to submit current apps right here, however I can present examples if wanted.
Thus far, I’ve tried the next:
Possibility 1: Customized UINavigationController
subclass
One thing just like the reply right here, the place the containing navigation controller returns a unique worth for supportedInterfaceOrientations
relying on the topmost controller. This works however violates (1) and (2) – there’s all the time an animation when presenting or dismissing a view controller that requires a unique orientation than the earlier one.
I additionally tried presenting the modal from a clear nested/baby view controller, however that has comparable limitations.
Possibility 2: A number of UIWindows
(extra promising)
As a substitute of presenting VC-B immediately from VC-A (or a standard mother or father), create a brand new, clear UIWindow
and use its rootViewController
to current the modal. This solves (1) and (2) superbly:
Nevertheless, it fails at (3) as a result of the sheetPresentationController
not includes VC-A. As a substitute, the clear rootViewController
is animated, leading to a clear shadow on high of VC-A:
This shadow/dimming might be prevented by setting largestUndimmedDetentIdentifier
to .giant
:
Nevertheless, I simply wish to apply that impact to VC-A, not get rid of it fully. The top end result ought to look identical to it does when no separate UIWindow
is concerned:
I can consider some potential workarounds, however I am probably not positive tips on how to proceed. I’ve tried presenting a clear view controller (name it VC-C) from VC-A concurrently presenting VC-B from the opposite UIWindow
. This creates the phantasm that VC-B is being offered from the identical view hierarchy as VC-A (by inflicting VC-A to have the push down impact I would like), however complicates dismissal. It is trivial sufficient to make sure that each sheets are dismissed on the identical time if dismiss()
is used immediately, but when the person drags down on VC-B, it appears fairly troublesome to get VC-C to sync with that movement.
Is there another method or API I am lacking? Perhaps some thriller configuration of UISheetPresentationController
that I’ve ignored, or a intelligent means to make use of customized transitions? Some strategy to mirror the contents of VC-A into the opposite window’s `rootViewController? Once more, this needs to be very potential as I’ve seen it occur within the wild.