Ios 旋转时RotateFromInterface定向是否未触发?

Ios 旋转时RotateFromInterface定向是否未触发?,ios,ipad,rotation,Ios,Ipad,Rotation,可能重复: 我的viewcontroller子类中没有触发didRotateFromInterfaceOrientation方法,这使我遇到了问题 我有一个iPad应用程序,主视图是UISplitViewController。在细节方面,我使用一个“隐藏”(没有工具栏,导航栏)导航控制器来进行惰性视图切换。我想要捕捉DidRotateFrominerFaceOrientation的ViewController在navcontroller层次结构中有两个层次。(所有这些都不会有什么不同,但我会提

可能重复:

我的viewcontroller子类中没有触发didRotateFromInterfaceOrientation方法,这使我遇到了问题

我有一个iPad应用程序,主视图是UISplitViewController。在细节方面,我使用一个“隐藏”(没有工具栏,导航栏)导航控制器来进行惰性视图切换。我想要捕捉DidRotateFrominerFaceOrientation的ViewController在navcontroller层次结构中有两个层次。(所有这些都不会有什么不同,但我会提供这些信息,以防有我不知道的特殊情况)

我有:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

// This doesn't work. :(
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    NSLog(@"Rotate Go!");
}
视图旋转得很好,但didRotateFromInterfaceOrientation从不激发


你知道我错过了什么吗?

嗯,我从来没有弄清楚为什么没有触发事件,但我确实找到了解决办法:


在两个
UISplitViewController
委托方法中,
splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
splitViewController:willShowViewController:InvalizationBarbuttonItem:
,我正在检测我的视图是否可见,然后在这里执行我的旋转逻辑。

如果UIViewController是某个根视图中的子控制器,则默认情况下IB不会将其作为子控制器添加到根控制器中。解决此问题的最简单方法是修改根控制器:

- (void)viewDidLoad
{
    [super viewDidLoad];    
    [self addChildViewController:(UIViewController*) self.yourChildController];
}  
这应该能奏效。现在,您的子控制器将同时接收:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;


信息。

您有uitabbar吗?因为如果是,您应该创建一个uitabbar类,并在该类中实现“shouldAutorotateToInterfaceOrientation”,以便所有其他控制器接收旋转消息。Nope。我使用的是UISplitViewController,带有UIToolbar和UINavigationController(工具栏隐藏,因此不同的视图共享另一个工具栏)。但是没有UITabBar…根据苹果公司的说法,您的UISplitViewController必须是应用程序窗口中的根视图。如果不是这样的话,你可能会经历一些奇怪的事情。选中此选项,使线程My
UISplitViewController
成为窗口的根视图。我确保从我的所有子视图中返回YES到
shouldAutorotateToInterfaceOrientation
。实际的旋转效果很好,只是从来没有调用过
didRotateFromInterfaceOrientation
。所以,再问几个问题,让它更清楚。您的控制器是否扩展了
UIViewController
以外的任何类?您是在推送您的
UIViewController
还是只是将控制器视图添加为另一个控制器的子视图?您在
shouldAutorotateToInterfaceOrientation
处返回YES,但是当您旋转时是否真的调用了此方法,还是仅在
didRotateFromInterfaceOrientation
处调用了此方法?谢谢!这刚刚修复了我在UISplitViewController中遇到的一个问题,即无法获取旋转事件。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;