4

UIAlertView と UIActionSheet だけでなく、UITabBarViewController のpushViewController:animated、 、およびタブ スイッチなどのメソッドが使用されている場合に、ビュー階層で何が起こるかを理解しようとしています。presentModalViewController:animated

(補足: これを行っているのは、自分の作成した特定の UIView が画面に表示されているかどうかを知る必要があるためです。その UIView またはそのスーパービューがビュー階層にどのように追加されたかについては何も知りません。誰かが知っている場合これを判断する良い方法です。知識を歓迎します。)

それを理解するために、さまざまな状況で [[UIApplication sharedApplication] keyWindow] サブビューの階層をログアウトしてきました。次は正しいですか。

  1. 新しい viewController が UINavigationController のスタックにプッシュされると、古い viewController のビューはビュー階層になくなります。つまり、最上位のビュー コントローラーのビューのみが UINavigationController のビューのサブビューです (ログによると、実際には UILayoutContainerView などのいくつかのプライベート クラスです)。スタックの最上位コントローラの下にあるビュー コントローラのビューは、実際にウィンドウから削除されていますか?

  2. 新しい viewController が を介して提示されると、非常によく似たことが起こりpresentModalViewController:animatedます。新しい viewController のビューは、キュー ウィンドウの唯一のサブビューです。これは正しいです?

  3. 理解するのが最も簡単なこと: UIAlertView は独自のウィンドウを作成し、それをキーにします。

  4. 私が遭遇した最も奇妙なこと: UIActionSheet はshowInView:メソッドを介して表示され、actionSheetはビュー階層にまったくありません。に引数として渡されたビューのサブビューでshowInView:はなく、キー ウィンドウのサブビューとして追加されず、独自のウィンドウを作成しません。では、どのように表示されますか?

  5. これはまだ試していないので、UITabBarController のタブが切り替えられたときに keyWindow 階層で何が起こるか知りたいです。選択した UIViewController のビューは一番上に移動しますか?それとも、表示されたビューだけがウィンドウ階層にあるpushViewController:animatedとのように機能しますか?presentModalViewController:animated

4

3 に答える 3

1

I think you're conceptually confusing views and views controllers. Both the navigation controller and the tabbar controller manager other view controllers. Neither manages views.

There is no view hierarchy for an entire app, there is only a hierarchy of view controllers. A view hierarchy only exist when each controlled view is loaded. Then you have a temporary hierarchy of window-->viewController.view-->viewController.view.subviews. When you push/pop another view controller on the stack, you get another view hierarchy.

The view hierarchy is an stage illusion that the user sees. The view controller hierarchy is the stage-set/backstage that the programer uses to create that illusion. Don't confuse the two.

So:

  1. Are the views of view controllers below the top controller of the stack actually removed from the window? Yes. When the view controller is popped off the stack its view disappears. Why waste memory holding a view that the user may never see again?
  2. The new viewController's view is the only subview of the kew window. Is this correct? Yes.
  3. ...a UIAlertView creates its own window and makes it key. Yes.
  4. ...the actionSheet isn't in the view hierarchy at all. ... How does it appear, then? It's added by the application above the window. That's what makes it special. It's also what makes is able to appear above all other views even when those views fail.
  5. Is the view of the selected UIViewController moved to the top Yes. Again, stage illusion. You swap out the one controllers view for another controller's view.
于 2010-03-19T12:39:41.303 に答える
0

UITabBarViewControllerに対して同じ種類のロギングを実行したので、パート5を検討します。

UINavigationControllerと同じように機能するようです。現在アクティブなタブに関連付けられているViewControllerのビューのみが、keyWindowのビュー階層にあります。

于 2010-03-19T02:40:05.473 に答える
0

UIView の次のメソッドは、必要なことを実行できます。

– didAddSubview:
– didMoveToSuperview
– didMoveToWindow
– willMoveToSuperview:
– willMoveToWindow:
– willRemoveSubview:
于 2010-03-27T14:45:38.483 に答える