“didRotateFromInterfaceOrientation:”没有被调用

发布于 2024-12-09 03:00:27 字数 101 浏览 0 评论 0原文

您好,我正在尝试在主视图的小视图中添加子视图控制器的视图 但是 didRotateFromInterfaceOrientation: 。子控制器的未调用,因此我无法对方向的变化进行任何更改

hi i am traying to add subview a controller's view in a small view of the main view
but the didRotateFromInterfaceOrientation:. of the child controller isnt called so i canot make any changes for the change in the orientation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

白首有我共你 2024-12-16 03:00:27

仅当您将 childViewController 添加到 ParentViewController 时,才会调用 didRotateFromInterfaceOrientation (在 childViewController 中):

[parentViewController addChildViewController:childViewController];

请注意,您仍然可以使用属性打开/关闭该行为:

self.automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers

将其设置为 YES默认,所以在你的情况下你不需要碰它。
iOS 6.0 后已弃用
干杯

didRotateFromInterfaceOrientation will be called (in childViewController) only if you add childViewController to parentViewController like this:

[parentViewController addChildViewController:childViewController];

Note that, you still can switch that behavior on/off with a property:

self.automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers

It is set to YES by default, so in your case you don't need to touch it.
Deprecated after iOS 6.0
Cheers

梦里梦着梦中梦 2024-12-16 03:00:27

您是否有超过 1 个 UIViewController 同时在屏幕上主动显示其视图? iOS 实际上只期望屏幕上同时出现 1 个属于 UIViewController 的视图。如果超过 1 个,则只有视图为全屏的 UIViewController 才会调用其方向更改方法。

Do you have more than 1 UIViewController actively displaying its view on the screen at the same time? iOS really only expects 1 view belonging to a UIViewController on the screen at once. If there is more than 1 then only the UIViewController whose view is full screen will get its orientation change methods called.

比忠 2024-12-16 03:00:27

我只是想发布这个问题的后续内容。在 iOS 8 之后,旋转方法已被弃用,而是您在子视图控制器中重写 viewWillTransitionToSize() 。

注意:此方法似乎确实需要您添加如上所述的子视图控制器。我使用故事板和导航控制器构建了测试,并在按下按钮时推送了新的视图控制器。

我在这个函数上设置了一个断点,当我使用调试器检查: self->parentViewController->childViewControllers 时,childViewControllers 为零。

I just wanted to post a follow up to this question. Post iOS 8, the rotate methods have been deprecated and instead you override viewWillTransitionToSize() in the child view controller.

NOTE: This method does appear to need you to add the child view controller as described above. I built my test using a storyboard and NavigationController and pushed on a new view controller when a button was pressed.

I set a breakpoint on this function and when I used the debugger to inspect: self->parentViewController->childViewControllers, childViewControllers was nil.

苍风燃霜 2024-12-16 03:00:27

我也有同样的问题。基本上,该方法

didRotateFromInterfaceOrientation:

是为根/父视图控制器调用的,如果您希望为视图控制器调用此方法,那么它必须是当前根视图控制器的子视图控制器。

 [self addChildViewController:YourUIViewController];

I had the same problem. Basically the

didRotateFromInterfaceOrientation:

is called for the root/parent view controller and If you are expecting this method getting called for a view controller, then the it must be child view controller of the current root view controller.

 [self addChildViewController:YourUIViewController];
宫墨修音 2024-12-16 03:00:27

根据 Apple 文档,“当可见视图控制器发生旋转时,在旋转期间会调用 willRotateToInterfaceOrientation:duration:、willAnimateRotationToInterfaceOrientation:duration: 和 didRotateFromInterfaceOrientation: 方法。在视图调整大小和位置后,也会调用 viewWillLayoutSubviews 方法。如果发生方向更改时视图控制器不可见,则永远不会调用旋转方法。当视图变得可见时,将调用 viewWillLayoutSubviews 方法。此方法的实现可以调用 statusBarOrientation 方法来确定设备方向。”

但实际上,即使视图可见,由于某种原因(也许是因为视图没有全屏?),相应的视图控制器的旋转相关委托方法也不会被调用。
覆盖 -viewWillLayoutSubviews 可能是某些情况下的解决方法。

Per Apple document "When a rotation occurs for a visible view controller, the willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are called during the rotation. The viewWillLayoutSubviews method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the device orientation."

But actually, even when the view is visible, for some reason (maybe because the view is not taking the full screen?), corresponding view controller's rotation related delegate methods won't be called.
Overriding -viewWillLayoutSubviews might be a workaround for some cases.

勿忘心安 2024-12-16 03:00:27

这是控制器的寿命问题。我怀疑您实例化了控制器并添加了子视图,然后释放了实例。现在,如果您正在旋转设备,则不会调用添加的子视图旋转委托方法。

第二个原因是,每当您添加子视图时,只会调用父视图委托,因为调用者只有父视图控制器的实例。调用者可以是导航控制器(基于导航的应用程序)、选项卡控制器(在基于选项卡的应用程序的情况下)。如果你想在旋转中调用子视图方法,你需要像下面这样显式调用它:

if(subviewController != nil){

  if([subviewController respondToSelector(rotateMethodOfSubView:)])

     [subViewController performSelector(rotateMethodOfSubView:) withObject: self];

} 

这应该有助于解决问题。

It's a problem of life of the controller. I suspect that you instantiated the controller and added the subview then released the instance. Now if you are rotating the device you are not getting called the added subview rotation delegate methods.

Second reason is whenever you added the subview only parent view delegate will be called because the caller only have instance of the parentview controller. Caller may be navigation controller (navigation based application), tabbarcontroller (in case of tab based application). If you want to call subview method in the rotation you will need to call it explicitly like following:

if(subviewController != nil){

  if([subviewController respondToSelector(rotateMethodOfSubView:)])

     [subViewController performSelector(rotateMethodOfSubView:) withObject: self];

} 

This should be helpful to solve the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文