我在有 4 个标签的 iPhone 应用程序中使用标签栏控制器。我已经为这两个方向编写了代码。
问题是当我将标签从纵向视图切换到横向视图时我遇到了麻烦。例如。如果我处于 tab1 横向模式,现在我切换标签并移动到 tab2 横向模式,但我可以看到该特定视图的纵向设置,而不是横向视图。
到目前为止,包含标签栏控制器的启动视图控制器上的代码如下:
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
if (self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft)
{
[self rotatingLandscape];
}
else if (self.interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
[self rotatingLandscape];
}
if (self.interfaceOrientation==UIInterfaceOrientationPortrait)
{
[self RotatingPotrait];
}
else if (self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
[self RotatingPotrait];
}
[super viewWillAppear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationPortrait)
{
rotate=YES;
[self RotatingPotrait];
}
if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
rotate=YES;
[self RotatingPotrait];
}
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
rotate=NO;
[self rotatingLandscape];
}
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
rotate=NO;
[self rotatingLandscape];
}
return YES;
}
-(void)rotatingLandscape
{
int selIndex = [self.tabBarController selectedIndex];
if (selIndex == 0)
{
[view1p rotatingLandscape];
}
else if (selIndex == 1)
{
[view2 rotatingLandscape];
}
else if (selIndex == 2)
{
[view3 rotatingLandscape];
}
else if (selIndex == 3)
{
[view4 rotatingLandscape];
}
self.tabBarController.view.frame=CGRectMake(0, 0, 480, 300);
}
-(void)RotatingPotrait
{
int selIndex = [self.tabBarController selectedIndex];
if (selIndex == 0)
{
[view1p RotatingPotrait];
}
else if (selIndex == 1)
{
[view2 RotatingPotrait];
}
else if (selIndex == 2)
{
[view3 RotatingPotrait];
}
else if (selIndex == 3)
{
[view4 RotatingPotrait];
}
self.tabBarController.view.frame=CGRectMake(0, 0, 320, 460);
}