嘿,我现在自己想出了一个解决方法。概括问题 只有窗口的第一个附加视图才能识别方向更改。
我将我的 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 的“viewControllers”仍然无法识别我的 InterfaceOrientations。所以我想出了以下内容:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
for (int i = 0; i < [self.viewControllers count]; i++ ) {
[[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
}
这将从 TabBarController 的所有子类中调用 didRotateFromInterfaceOrientation 方法:
- (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
}
}
如您所见,我调用[self adjustViewsForOrientation:self.interfaceOrientation];
了我的子视图控制器,它将为调整方法提供实际的方向。如果您使用 fromInterfaceOrientation 将是错误的方向,因为更改已经完成!
我的另一个问题是 TabBarController 中的 UISplitviewController,但我没有让它以可接受的方式工作。问题与 UIViewControllers 相同。它不会重新识别方向变化,所以你必须对它进行子类化,但我没有让它工作到 100%。当我在网上搜索时,我发现了一个很好的代码示例,用于 cutsom 构建 Splitview。所以你可能会试一试:http:
//blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait
http://www.trustedones.com/apps/ipad
它还将 SplitView 保持在纵向模式,因此您可能会喜欢它。我愿意!
希望我能在这篇文章中帮助某人.. 干杯 nettz