Ipad UIAbbarController中的UIViewController和UIPlitViewController应自动旋转指向面方向
我的iPad代码有一些问题 我有一个UIAbbarController,其中包含一些UIViewController和一个UIPlitViewController。问题是UIViewController甚至UISplitViewController都无法正确识别方向更改 我已经在我的Tabbar控制器和所有UIViewController上设置了shouldAutorotateToInterfaceOrientation,但我意识到只有最上面的ViewController中的willRotateToInterfaceOrientation才会启动,这就是我的Tabbar控制器。如果从Tabbar中删除shouldAutorotateToInterfaceOrientation,则会调用子UI中的控制器RotateToInterfaceOrientation。最大的问题是我的UISplitViewController,因为它将旋转到新的界面方向,但它在他的肖像布局中受阻Ipad UIAbbarController中的UIViewController和UIPlitViewController应自动旋转指向面方向,ipad,uiviewcontroller,uitabbarcontroller,rotation,uisplitviewcontroller,Ipad,Uiviewcontroller,Uitabbarcontroller,Rotation,Uisplitviewcontroller,我的iPad代码有一些问题 我有一个UIAbbarController,其中包含一些UIViewController和一个UIPlitViewController。问题是UIViewController甚至UISplitViewController都无法正确识别方向更改 我已经在我的Tabbar控制器和所有UIViewController上设置了shouldAutorotateToInterfaceOrientation,但我意识到只有最上面的ViewController中的willRotate
如何正确实现带有ViewController和SplitView(包括方向更改)的TabBarController?嘿,我自己想出了一个解决方法。 为了重述问题,只有窗口的第一个addet视图才能识别方向更改 我将TabBarController子类化,并使其旋转到接口方向
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Landscape");
//Do Your Landscape Changes here
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"Portrait");
//Do Your Portrait Changes here
}
}
但是现在我的TabBarController的“视图控制器”仍然无法识别我的界面方向。因此,我提出了以下建议:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
for (int i = 0; i < [self.viewControllers count]; i++ ) {
[[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
}
如您所见,我调用[self-adjustViewsForOrientation:self.interfaceOrientation]代码>在我的子Viewcontroller中,它将为调整方法提供实际方向。如果您使用fromInterfaceOrientation,它将是错误的方向,因为更改已经完成
我的另一个问题是TabBarController中的UISplitviewController,但我没有让它以可接受的方式工作。问题与UIViewController的问题相同。它不会重新组织方向更改,所以您必须对其进行子类化,但我没有让它100%工作。当我在网上搜索时,我找到了一个cutsom build Splitview的好代码示例。所以我可以试试看:
它还将SplitView保持在纵向模式,因此您可能会喜欢它。我知道
希望我能在这篇文章上帮助别人。。
干杯
nettz注意,UITabBarController类引用的第二句话指出“该类不用于子类化。”
因此,虽然这种方法可能有效,但我怀疑它不是“正确”的方法。(我也有这个问题。)你有没有想过如何让它完全按照你想要的方式工作?
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[self adjustViewsForOrientation:self.interfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Subview Landscape");
//Do Your Landscape Changes here
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"Subview Portrait");
//Do Your Portrait Changes here
}
}