1

UINavigationBar通过改变它的框架来改变它的高度。但是如果我将应用程序发送到后台然后再次打开它,它的高度就会恢复到原来的大小。我该如何解决?

4

1 回答 1

0

您可以将框架写入资源文件,如 plist 或 XML 文件。-(void)applicationWillEnterForeground:(UIApplication *)application' or然后在-(void)applicationDidBecomeActive:(UIApplication *)application`的应用程序委托文件中加载 plist 。我相信你也可以使用 NSUserDefaults:

NSUserDefaults *frameSize = [NSUserDefaults standardUserDefaults];

//Put frame size into defaults
[sharedDefaults setObject:navigationBar.frame forKey:@"frame"];
[sharedDefaults synchronize];

然后在前面提到的 App Delegate 方法中,您可以执行以下操作:

self.viewController.navigationController.frame = [sharedDefaults objectForKey:@"frame"];

希望这会有所帮助,如果有帮助,请记得投票。

- - - - - -编辑 - - - - - -

如果您查看这个问题iOS selected tab,它会告诉您如何确定选择了哪个选项卡。他们基本上说的是首先添加self.tabController.delegate = self应用程序委托,并确保应用程序委托和带有标签栏的视图控制器符合 UITabBarControllerDelegate 协议。然后在带有标签栏的 View Controller 文件中,您可以使用协议中定义的此方法:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    if (tabBarController.selectedIndex == 0) { 
    //The 0 is the first tab, but you can replace that with any other tab's index

         //Here you say that when said tab is selected, the navigation controller's frame is the stored length.
         self.navigationController.frame = [sharedDefaults objectForKey:@"frame"]; 
    }
    else{
         self.navigationController.frame = CGRectMake(frame, for, other, tabs);
    }
} 
于 2012-06-02T21:59:21.550 回答