嘿,我现在自己想出了一个解决方法。
回顾一下问题 只有窗口的第一个附加视图才能识别方向更改。
我对 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];
在我的子视图控制器中,它将为调整方法提供实际的方向。如果您使用InterfaceOrientation,它将是错误的方向,因为更改已经完成!
我的另一个问题是 TabBarController 中的 UISplitviewController,但我没有让它以可接受的方式工作。问题与 UIViewController 相同。它不会重新识别方向变化,所以你必须对它进行子类化,但我没有让它工作到 100%。当我在网上搜索时,我发现了一个关于 cutsom 构建 Splitview 的很好的代码示例。所以我们也许会尝试一下:http://blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait http://blog.trustedones.com/development/ipad-uisplitviewcontroller-replacement-for-sethidesmasterviewinportrait
http://www.trustedones.com/apps/ipad http://www.trustedones.com/apps/ipad
它还将分屏视图保持在纵向模式,因此您可能会喜欢它。我愿意!
希望我可以帮助某人完成这篇文章..
干杯
内茨