What object is responsible for dipatching the UIViewController
rotation method calls, i.e:
shouldAutorotateToInterfaceOrientation:
This is all Magic You Don't Ever Worry About. Just add your controller's root view to the window--or get a tab bar or navigation controller to do it for you--and it will receive these messages.
(But if you poke around with the debugger, you might come to the same conclusion I have: there's some sort of internal table mapping each controller's view back to the controller, and the messages are dispatched based on that link.)
Update: This was truly private magic in 2009 when I first wrote this answer, but subsequent changes to iOS have made the APIs behind it public. The root view controller is now accessible through the UIWindow.rootViewController
property, and the tree of descendant view controllers is formed using the UIViewController.childViewControllers
property.
Parent view controllers are responsible for notifying their children of orientation changes. (I'm not sure how the root view controller is notified, but you could set a breakpoint and find out yourself.) The -shouldAutomaticallyForwardRotationMethods
method decides whether UIViewController will do this for you. If it returns NO
, you become responsible for doing so in your -willRotateToInterfaceOrientation:duration:
, -willAnimateRotationToInterfaceOrientation:duration:
, and -didRotateFromInterfaceOrientation:
methods.