0

我已经准备好我的 iPhone 应用程序,现在我必须让它成为一个通用应用程序。

我在做这个。。

self.window = [[UIWindow alloc] init];
self.appFrame = [[UIScreen mainScreen] bounds];
self.window.frame = self.appFrame;
UINavigationController *aNav = [[UINavigationController alloc] initWithRootViewController:self.myViewController];
aNav.view.frame = self.appFrame; 
self.nav = aNav;
[self.window addSubview:nav.view];
[self.window makeKeyAndVisible];

我的项目中没有MainWindow.xib。我正在以编程方式创建它。

因此,如果我使用此代码将框架提供给窗口

self.appFrame = [[UIScreen mainScreen] bounds];
self.window.frame = self.appFrame;

那么iPad应该有(0,0,768,1024),iPhone应该有(0,0,320,480)

但是,如果我在 iPad 模拟器上运行我的代码,它self.appFrame需要(0,0,320,480)

你们能解释一下是什么问题吗??

如何在不使用的情况下创建通用应用程序MainWindow.xib

4

1 回答 1

0

在 Xcode 中打开目标的 Build Settings 选项卡,并将Targeted Device Family键设置为iPhone/iPad。然后您的应用程序编译为原生 iPad 和 iPhone 应用程序,并[[UIScreen mainScreen] bounds]应返回正确的结果。顺便说一句,您应该使用[[UIScreen mainScreen] applicationFrame]而不是窗口框架的边界!

于 2011-08-03T13:47:09.520 回答