Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

iphone - UIViewController rotate methods

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

  • shouldAutorotateToInterfaceOrientation:
  • willRotateToInterfaceOrientation:duration:
  • willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
  • willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
  • didRotateFromInterfaceOrientation:

I imagine it is UIApplication (but maybe the AppDelegate or UIWindow).

The next question, is how does the object know which UIViewController to talk to?

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

Is there a message you can send or a property you can set (of some object) that sets the "Active" UIViewController for the app?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It seems that UIApplication is dispatching a message to the active view controller.

But how does your View Controller instance get these messages?

The message is forwarded to the first view controller whose view has been added to the UIWindow instance.

This boils down to 3 basic scenarios:

  1. The ViewController whose view is added directly to the UIWindow instance (single view app)

  2. The navigation Controller in a Navigation based app, then the navigation controller forwards the message to the active views view controller.

  3. The tab bar Controller in a tab bar based app, then the tab bar controller forwards the message to the active views view controller (or the active navigation controller).

The problem you will have, is if you build an app with multiple views, but DO NOT use a Navigation controller or Tab Bar controller. If you swap views in and out of the UIWindow instance manually, you will not receive these messages reliably. This is similar to posts like this one: iPhone viewWillAppear not firing

Just use Apple's conventions for multiple views and you be fine. Hope this saves some one an hour or two


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...