ios - Clarifications on managing orientations in UIViewController -
i have configuration following:
uinavigationcontroller -> viewcontroller
where viewcontroller
root view controller navigation controller.
viewcontroller
can present modally view controller, modalviewcontroller
, following.
self.presentviewcontroller(modalviewcontroller, animated: true, completion: nil)
within modalviewcontroller
override following method. modal view controller in fact can presented in landscape
mode.
override func supportedinterfaceorientations() -> uiinterfaceorientationmask { return .landscape }
i override viewcontroller
's method responding orientation changes.
override func viewwilltransitiontosize(size: cgsize, withtransitioncoordinator coordinator: uiviewcontrollertransitioncoordinator) { super.viewwilltransitiontosize(size, withtransitioncoordinator: coordinator) print("size \(size)") }
what noticed if modal view controller presented, print
in viewcontroller
logged if modalviewcontroller
in landscape
mode, while no logged in portrait
. in other words, while rotate device, modalviewcontroller
should able display landscape
orientations only. under hood, if viewcontroller
not visible (and device in portrait
), controller should able respond size changes. not case since cannot see print
log.
use case:
if modalviewcontroller
not visible print log
size (1024.0, 768.0) size (768.0, 1024.0) size (1024.0, 768.0) size (768.0, 1024.0)
when modalviewcontroller
presented modally
size (1024.0, 768.0) size (1024.0, 768.0)
is 1 correct behaviour? goal respond orientation changes viewcontroller
if (when modalviewcontroller
opened) device in portrait mode. clue?
edit
based on matt comment.
if viewcontroller not frontmost view controller has no business "responding orientation changes". you've merely stumbled across implementation detail or edge case in should have no interest.
viewcontroller
complex controller acts parent view controller. has 2 children: portraitviewcontroller
, landscapeviewcontroller
. these controllers swapped in viewwilltransitiontosize
method. whenever modalviewcontroller
not visible (not presented) swapping works in correct manner. on contrary, when modalviewcontroller
presented, swapping runs landscape
mode (see logs above).
it sounds me if you're trying @ wrong time. when modal view controller dismissed , view controller's view reappear, you'll plenty of warning (including appear
, layout
events) , can whatever needs doing, based on current orientation, before view becomes visible user.
Comments
Post a Comment