gpt4 book ai didi

ios - 如何在 xib 的 appdelegate 中检查设备是 ipad 还是 iphone?

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:05 24 4
gpt4 key购买 nike

这是我的didFinishLaunchingWithOptions:
目前我的应用程序仅适用于 iPhone,但我想要这两个(通用)。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
playerScreenViewController *playerScreen=[[playerScreenViewController alloc] initWithNibName:@"playerScreenViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:playerScreen];
self.window.rootViewController = navigationController;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.window.backgroundColor = [UIColor grayColor];
[self.window makeKeyAndVisible];
return YES;
}

而且我不知道如何在 appdelegate 中使用这个条件:

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// iPad
} else {
// iPhone
}

最佳答案

正如我在代码中看到的,您正在为 playerScreenViewController 使用 Xib。现在您需要为 iPad 环境创建 Xib

然后像这样放置你的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

playerScreenViewController *playerScreen;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// iPad
playerScreen=[[playerScreenViewController alloc] initWithNibName:@"playerScreenViewController_iPad" bundle:nil];

} else {
// iPhone
playerScreen=[[playerScreenViewController alloc] initWithNibName:@"playerScreenViewController" bundle:nil];

}

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:playerScreen];
self.window.rootViewController = navigationController;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.window.backgroundColor = [UIColor grayColor];
[self.window makeKeyAndVisible];
return YES;
}

观察这一行

playerScreen=[[playerScreenViewController alloc] initWithNibName:@"playerScreenViewController_iPad" bundle:nil];

这里你必须为 iPad 环境传递 Xib 名称。

关于ios - 如何在 xib 的 appdelegate 中检查设备是 ipad 还是 iphone?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26398729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com