UIViewController rotate methods

前端 未结 4 2070
南方客
南方客 2020-12-13 10:45

What object is responsible for dipatching the UIViewController rotation method calls, i.e:

  • shouldAutorotateToInterfaceOrientation:
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 11:25

    How does it know which UIViewController has its view as the subview of the window?

    UIViewController class maintains a static map between views and their view controllers. This map is queried in a few key places inside CocoaTouch. In particular, [UIView nextResponder] queries it and returns the controller if found.

    I guess UIWindow does the same lookup with its root view to know which controller to forward rotation events to. Will check this next time I'll be looking something up in the disassembly. (I've spent some time reverse-engineering CocoaTouch to understand how things work there.)

提交回复
热议问题