你並不需要改變窗框中的AppDelegate。
我會告訴你的代碼,請跟着它
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.mxfirstciewcontroller = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.mxfirstciewcontroller];
[(UINavigationController *)self.window.rootViewController setNavigationBarHidden:YES];
return YES;
}
在firstViewController.m
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.view setFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height)];
}
在secondViewController.m
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self.view setFrame:CGRectMake(20, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
你不應該改變這個框架窗口,但底層視圖的框架!請注意,自從iOS7以來,我們在每個視圖控制器上都有edgesForExtendedLayout屬性來處理這種行爲。此外,在故事板中,您可以取消選擇「延伸邊緣 - 頂部酒吧」等,以獲得您想要的 – Alexander
@ Alexander,我將此代碼添加到我的項目中,但無法使用! if([[[UIDevice currentDevice] systemVersion] floatValue]> = 7.0){self.edgesForExtendedLayout = UIRectEdgeNone; self.extendedLayoutIncludesOpaqueBars = NO; } – nang531
您是否使用導航控制器作爲容器?如果沒有,我會建議這樣做(你可以隱藏欄)請參閱http://stackoverflow.com/questions/18912290/how-to-present-a-view-controller-on-ios7-without-the-status-酒吧重疊 – Alexander