Ios 内容不';如果我使用UINavigationController,请不要旋转
如果我在应用程序中使用UINavigationController,则应用程序内容不会旋转。只有状态栏方向会更改 这是我的didFinishLaunchingWithOptions方法Ios 内容不';如果我使用UINavigationController,请不要旋转,ios,uinavigationcontroller,screen-orientation,Ios,Uinavigationcontroller,Screen Orientation,如果我在应用程序中使用UINavigationController,则应用程序内容不会旋转。只有状态栏方向会更改 这是我的didFinishLaunchingWithOptions方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:@"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.window setRootViewController:navigationController];
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window.rootViewController =nil;
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:@"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
return YES;
}
我不明白为什么我会得到这个结果
找到了它
最后,我找到了一个解决办法。但我不明白为什么
这是我的didFinishLaunchingWithOptions方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:@"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.window setRootViewController:navigationController];
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window.rootViewController =nil;
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:@"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
return YES;
}
这是SpecificViewController的viewDidLoad方法
- (void)viewDidLoad {
[super viewDidLoad];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
self.navigationItem.title=@"The Title";
}
我在plist文件中将“基于视图控制器的状态栏外观”属性设置为NO。
它现在起作用了,但我不明白这一切意味着什么以及为什么。这对我来说很有效,请尝试:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:@"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
}
将此添加到SpecificViewController.m
- (BOOL)prefersStatusBarHidden
{
return NO;
}
将“基于视图控制器的状态栏外观”属性设置为“是”,并从主界面选项中删除“Main”。您不需要使用setStatusBarHidden方法。我认为您接受的答案在这里并不正确,我想如果它对您有效,这很好,但我仍然认为它是错误的 旋转不起作用的原因是因为您正在使用自动创建UIWindow的故事板。然后,在应用程序的didfishLaunching方法中,您分配了一个新的UIWindow。只有第一个UIWindow(由您的故事板创建)将接收旋转通知,这就是为什么您只注意到状态栏旋转而没有注意到视图 解决方案是从
didfishlaunchwithoptions
方法中删除以下行:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
您的rootViewController也将在情节提要中设置,无需在代码中再次设置。您缺少
[self.window makeKeyAndVisible]您的中的code>使用选项完成启动。