简体   繁体   English

查看控制器层次结构和设备方向更改

[英]view controller hierarchy and device orientation changes

When orientation changes occur and view controllers are subsequently notified of changes, does the entire of the root view and all its subviews receive these notifications? 当方向发生变化并随后将更改通知视图控制器时,整个根视图及其所有子视图是否都收到这些通知? I have created a root view and a subview to that root view. 我已经创建了一个根视图和该根视图的子视图。 Does the subview's controller (and any controllers of subviews in this hierarchy) receive all the rotation handling resulting from device orientation changes? 子视图的控制器(以及此层次结构中子视图的任何控制器)是否接收到由于设备方向更改而引起的所有旋转处理?

I ask because nested in this hierarchy is a UISplitViewController's view, and I suspect it is not receiving notification of device orientation changes. 我问,因为嵌套在此层次结构中的是UISplitViewController的视图,并且我怀疑它没有收到有关设备方向更改的通知。 ie I essentially have something like A -> B -> C in my view hierarchy where C is a UISplitViewController's view. 即,我的视图层次结构中基本上有A-> B-> C之类的东西,其中C是UISplitViewController的视图。

When orientation changes occur only the first view of the window will rotate together with its entire hierarchy. 当方向发生变化时,仅窗口的第一个视图将与其整个层次结构一起旋转。 In terms of viewControllers, the first view's viewController will get the orientation change events (and viewWill/DidAppear events) and all the viewControllers spawn by it. 就viewControllers而言,第一个视图的viewController将获取方向更改事件(以及viewWill / DidAppear事件),并由此产生所有viewControllers。 By spawn I mean a viewcontroller displayed using either as a tab of a uitabbarViewController, or added to a navigation controller, or displayed modally. 生成是指使用uitabbarViewController的选项卡显示或添加到导航控制器或以模态显示的Viewcontroller。 In other words if somewhere in your hierarchy you added a viewcontroller's view manually to the window or another view, that viewcontroller will not get any events. 换句话说,如果您在层次结构中的某个位置将视图控制器的视图手动添加到了窗口或其他视图,则该视图控制器将不会获得任何事件。

See this: why does viewDidAppear not get triggered? 看到这个: 为什么viewDidAppear没有被触发? same thing happens for orientations changes 方向改变也会发生同样的事情

So there are 2 possible causes: 因此,有两种可能的原因:

  • your uisplitviewController's view or any of its parent is added manually to the view hierarchy instead of pushing the viewcontroller (the view gets rotated but does not receive events) 您的uisplitviewController的视图或其任何父视图被手动添加到视图层次结构中,而不是推送视图控制器(视图旋转但不接收事件)
  • you added the view as a second child of the window (the view doesn't get rotated at all) 您将视图添加为窗口的第二个子视图(视图完全不会旋转)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设备方向更改时更改视图控制器 - changing view controller when the device orientation changes 设备方向更改时调整PDF查看大小 - Resize PDF View when device orientation changes 设备方向纵向仅适用于一个视图控制器 - Device orientation portrait only for one view controller 无法使用导航控制器在视图控制器上锁定设备方向 - Unable to lock device orientation on view controller with navigation controller 设备方向到statusBar方向更改 - device Orientation to statusBar Orientation changes 屏幕方向更改时,可以在以前的视图控制器上转换视图吗? - Possible to transform view on previous view controller when screen orientation changes? 设备方向更改时如何重新排列集合视图单元格 - How to rearrange collection view cell when device orientation changes 当设备方向迅速改变时,浮动操作按钮的视图不出现 - View of floating action button not appearing when device orientation changes in swift 设备方向改变时以编程方式重绘视图的简单方法 - Simple way to redraw view programatically when device orientation changes 对象在视图中以及设备方向更改后位置不正确 - Objects position incorrectly in view and after device orientation changes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM