[英]How to make a universal app from the “Empty Application” template?
我尝试重新编写一些较旧的应用程序,并希望从头开始。
基本上,我尝试从“空应用程序”模板开始,该模板只剩下AppDelegate.m / .h,我需要在iPad / iPhone之间进行自己的分离。
知道我如何在AppDelegate中执行此操作吗?
在较早的Xcode版本中,该程序为iPad / iPhone创建了单独的委托。
当您不得不以不同的方式处理iPhona和iPad时,可以使用以下内容查看您是哪一个:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// Do things for iPad
} else {
// Do things for iPhone
}
因此,您可以为iPad或iPhone使用不同的视图委托,或者如果它们的行为几乎相同,则可以使用相同的视图委托并在必要时使用先前的测试。 例如,您可以修改init方法以加载其他Xib文件:
- (id)init
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self = [super initWithNibName:@"ViewController_iPad" bundle:nil];
} else {
self = [super initWithNibName:@"ViewController_iPhone" bundle:nil];
}
if (self) {
// Custom initialization
}
return self;
}
您可以在shouldAutorotateToInterfaceOrientation
等中执行类似的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.