我通过改变它的框架来改变UINavigationBar
的高度。但是,如果我将应用程序发送到后台然后再次打开它,它的高度会恢复到原来的大小。我该如何解决这个问题?
您可以将框架写入资源文件,如 plist 或 XML 文件。然后在应用程序委托文件中加载 plist,-(void)applicationWillEnterForeground:(UIApplication *)application' or
-(void)applicationDidBecomeActive:(UIApplication *)application'。我相信你也可以使用NSUserDefaults:
NSUserDefaults *frameSize = [NSUserDefaults standardUserDefaults];
//Put frame size into defaults
[sharedDefaults setObject:navigationBar.frame forKey:@"frame"];
[sharedDefaults synchronize];
然后在前面提到的应用程序委托方法中,您可以执行以下操作:
self.viewController.navigationController.frame = [sharedDefaults objectForKey:@"frame"];
希望这有帮助,如果有帮助,请记住投票。
-----------编辑------------
如果您查看此问题iOS选择选项卡,它会告诉您如何确定选择了哪个选项卡。他们基本上说的是首先在应用程序委托中添加self.tabController.delegate = self
,并确保应用程序委托和带有选项卡栏的视图控制器符合 UITabBarControllerDelegate 协议。然后在带有选项卡栏的视图控制器文件中,您可以使用协议中定义的此方法:
- (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);
}
}