willAnimateToRotation 没有被调用
我的 UIViewController 子类中有以下代码,但是从未调用 willAnimateROtationToInterface。知道为什么吗?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
更新: 父级的视图控制器方向更改委托正在被调用,但不是这个。我将此视图控制器添加为父视图控制器的子视图
父视图控制器是 UINavigationController,因此以下是我添加子视图的方法:
[self.navController.view addSubview:viewController.view];
I have the following code in my UIViewController subclass, however the willAnimateROtationToInterface is never called. Any idea why?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
UPDATE:
The parent's view controller orientation changes delegate is getting called however not this one. I added this view controller as a subview of the parent's view controller
The parent view controller is a UINavigationController, so here's how I am adding the subview:
[self.navController.view addSubview:viewController.view];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,这是视图控制器包含的问题,即
UIViewController
嵌套在另一个自定义UIViewController
子类中,该子类没有转发通知(或使用 iOS5 的>UIViewController
包含方法)。It turned out this was an issue with view controller containment, i.e. the
UIViewController
was being nested inside another customUIViewController
subclass, which was not forwarding the notifications (or using iOS5'sUIViewController
containment methods).您的 UIViewController 子类中是否存在以下任何方法?
如果是这样,您将沿着两部分路径前进,并且不会调用单部分方法
willAnimateRotationToInterfaceOrientation:duration:
。更新:
响应上面 xonegirlz 的更新:
父导航控制器(UINavigationController)不知道您的 UIViewController - 您已将视图层次结构中的视图链接在一起,但没有视图控制器 em> 一起在控制器层次结构中。
如果您的目标是 iOS 5,则可以在 UINavigationController 上调用
-[UIViewController addChildViewController:]
来通知其子级。对于 iOS 4,您需要使用
-[UINavigationController PushViewController:animated:
或-[UIViewController PresentModalViewController:animated:]
来设置正确的视图控制器层次结构。如果这不是一个选项,您需要对父视图控制器进行子类化,并手动将旋转方法转发到子视图控制器。
Do you have any of the following methods present in your UIViewController subclass?
If so you are going down the two-part path, and the one-part method
willAnimateRotationToInterfaceOrientation:duration:
will not be called.UPDATE:
In response to xonegirlz's update above:
The parent navigation controller (the UINavigationController) has no knowledge of your UIViewController - you have linked the views together in the view hierarchy, but not the view controllers together in the controller hierarchy.
If you are targetting iOS 5, you can call
-[UIViewController addChildViewController:]
on the UINavigationController to inform it of the child.For iOS 4, you need to use
-[UINavigationController pushViewController:animated:
or-[UIViewController presentModalViewController:animated:]
to setup the proper view controller hierarchy.If that's not an option, you need to subclass the parent view controller, and manually forward the rotation methods to your child view controller.