Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone';s UITabBar作为应用程序窗口的一部分;旋转设备时出现的问题_Iphone_Cocoa Touch_Uinavigationcontroller_Uitabbar_Device Orientation - Fatal编程技术网

iPhone';s UITabBar作为应用程序窗口的一部分;旋转设备时出现的问题

iPhone';s UITabBar作为应用程序窗口的一部分;旋转设备时出现的问题,iphone,cocoa-touch,uinavigationcontroller,uitabbar,device-orientation,Iphone,Cocoa Touch,Uinavigationcontroller,Uitabbar,Device Orientation,我有一个iPhone应用程序,它使用导航控制器来显示顶部栏(带有标题和后退按钮等…) 我在应用程序窗口中添加了一个uitabar,可以在各个部分之间切换。我没有将选项卡栏添加到ViewController的每个视图中,而是将选项卡栏添加到应用程序窗口中 (当我在ViewController中使用它时,在控制器之间切换使选项卡栏在发生动画弹出/推送以及整个视图时向左/向右滑动) 因此,我将uitabar添加到main window.xib,并将其绑定到app委托的变量。在我的didfishlaun

我有一个iPhone应用程序,它使用导航控制器来显示顶部栏(带有标题和后退按钮等…)

我在应用程序窗口中添加了一个
uitabar
,可以在各个部分之间切换。我没有将选项卡栏添加到ViewController的每个视图中,而是将选项卡栏添加到应用程序窗口中

(当我在ViewController中使用它时,在控制器之间切换使选项卡栏在发生动画弹出/推送以及整个视图时向左/向右滑动)

因此,我将
uitabar
添加到
main window.xib
,并将其绑定到app委托的变量。在我的
didfishlaunchingwithoptions
方法中,我添加了以下代码:

[self.window addSubview:navigationController.view];

CGRect frame = navigationController.view.frame;
frame.size.height -= tabbar.frame.size.height;
navigationController.view.frame = frame;
tabbar.selectedItem = [tabbar.items objectAtIndex:0];
调整主(
navigationController
)视图的大小,以使选项卡栏可见

当我旋转设备时,问题就出现了——我的视图被拉伸到整个窗口,我失去了显示选项卡栏的能力

我将InterfaceOrientation方法中的
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)添加到我的ViewController中,代码如下:

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    CGRect frame = self.view.frame;
    frame.size.height -= [AppState shared].tabBar.frame.size.height;
    //frame.origin.y = [AppState shared].tabBar.frame.size.height;
    //frame.origin.x = 100;
    self.view.frame = frame;    
    frame = [AppState shared].tabBar.frame;
    frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.origin.y - frame.size.height;
    [AppState shared].tabBar.frame = frame;
}
它调整视图的大小,并将选项卡栏移动到视图的上/下部分(此处仅允许纵向/纵向倒置方向)。问题是,我的标签栏也被颠倒了,而且,它不再可以点击

如下图所示:


有人知道如何处理这种情况吗?或者,如何使选项卡栏不绑定到视图控制器,而且能够平滑地处理界面的旋转

您无意中使用了选项卡栏。您似乎正在使用uitabarview作为其他视图的一个不受控制的元素。这不是它的功能

UITabBarView应由UITabBarController直接控制,而UITabBarController应控制选项卡栏中显示的视图的所有视图控制器,即选项卡栏控制器是一种导航控制器,用于控制子文件夹

假设您有三个选项卡,第三个选项卡是导航控制器。控制器层次结构如下所示:

TabbarController:
    -->tab1ViewController
    -->tab2ViewController
    -->tab3ViewController(UINavigationController):
            -->rootViewController-->secondViewController
您试图在没有控制器和适当的控制器层次结构的情况下移动和管理选项卡栏视图。那是行不通的