Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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-进入前台后如何恢复画面大小?_Iphone_Objective C_Ios_Xcode_Cocoa Touch - Fatal编程技术网

iPhone-进入前台后如何恢复画面大小?

iPhone-进入前台后如何恢复画面大小?,iphone,objective-c,ios,xcode,cocoa-touch,Iphone,Objective C,Ios,Xcode,Cocoa Touch,我通过更改其框架更改了UINavigationBar的高度。 但若我将应用程序发送到后台,然后再次打开它,它的高度会恢复到原来的大小。如何修复此问题?您可以将帧写入资源文件,如plist或XML文件。然后将plist加载到应用程序委托文件中的-(void)application将进入前台:(UIApplication*)应用程序”或-(void)applicationdidebomeactive:(UIApplication*)应用程序”。我相信您也可以使用NSUserDefaults: NSU

我通过更改其框架更改了UINavigationBar的高度。
但若我将应用程序发送到后台,然后再次打开它,它的高度会恢复到原来的大小。如何修复此问题?

您可以将帧写入资源文件,如plist或XML文件。然后将plist加载到应用程序委托文件中的
-(void)application将进入前台:(UIApplication*)应用程序”或
-(void)applicationdidebomeactive:(UIApplication*)应用程序”。我相信您也可以使用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"];
希望这有帮助,如果有,记得投票

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

如果您看这个问题,它会告诉您如何确定选择哪个选项卡。他们基本上说的是首先在app delegate中添加
self.tabController.delegate=self
,并确保app delegate和带有选项卡栏的视图控制器符合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);
    }
} 

你在哪里改变它的高度?您是否在ViewController的viewDidLoad中执行此操作?是的,在viewDidLoad和ViewDidDisplay中也应执行此操作一次,将其从ViewDidAppard中删除。是否找到解决方案?我的应用程序有4个选项卡,UINavigationBar高度应仅在其中一个选项卡中更改。我怎么做?我对标签栏不太熟悉,所以我现在恐怕帮不了你,但我会调查一下。因此,您也可以将选项卡索引保留在
nsserdefaults
中,作为
NSNumber
,如果您想保留所有选项卡框架,也可以将它们保留在
nsserdefaults
中,作为包含
NSNumber
对象的
NSMutableArray
对象或使用
NSMutableDictionary
等。。希望这能给你一些启发。