我有一个 tabBarController,上面有三个 viewController。When viewController 1 is selected and I make a 90 degrees I hide the tabBar and I have to addsubview the current view to the tabBarController, otherwise a blank space appears where the tabBar was.
如果现在我将 iPhone 旋转到以前的方向(垂直正常位置)我 removeFromSuperview 视图,但视图控制器上没有显示视图,我想应该显示原始视图(addsubview 调用之前的那个),事实上如果我选择第二个 viewController,然后我回到 viewController 1,则视图会完美显示。
我不明白为什么会发生这种情况,你能帮帮我吗?
更新:
我认为问题是我在 tabbarcontroller 上添加了一个视图(self.view addSubview:vista_AS.view])我需要这个来使 tabbar 不可见,后来,当我删除这个视图时,tabbarcontroller 以某种方式丢失了 viewcontroller 0 查看参考。我不明白的是,为什么当我更改为 viewcontroller 1 然后又回到 0 时,视图就可以了。有没有办法重新加载 viewcontroller 0 视图?
更新 2:从建议编辑到答案中包含作者的代码
这是我的代码:
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.tabBar.hidden = TRUE;
vista_AS = [delegate.tabBarController.viewControllers objectAtIndex:0];
vista_AS.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:vista_AS.view];
}
else {
if ( (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) )
{
[vista_AS.view removeFromSuperview];
self.tabBar.hidden = FALSE;
}