简体   繁体   English

使应用程序适用于iPhone和iPad

[英]Make an application work on both iPhone and iPad

I would like to make it so that my iPhone app also works on iPad. 我想这样做,以便我的iPhone应用程序也适用于iPad。

If I run it using the iPad simulator it does work, but the app doesn't show up on the iPad app store, and looks really weird. 如果我使用iPad模拟器运行它确实有效,但该应用程序没有出现在iPad应用商店中,看起来很奇怪。

Is it possible to create another .xib file for the iPad? 是否可以为iPad创建另一个.xib文件? I know how to add a new iPad .xib file, yet I don't know how to actually change the RootViewController.xib to RootViewController_iPad.xib if the device being used is an iPad. 我知道如何添加一个新的iPad .xib文件,但我不知道如何将真正改变RootViewController.xibRootViewController_iPad.xib如果正在使用的设备是一台iPad。

I already have code for finding out if the device is an iPad, and I don't want to use auto-layout , because I would like to add different things to the view if they are using an iPad (such as using different images). 我已经有代码,发现如果该设备是一个iPad,我希望使用auto-layout ,因为我想不同的事情,如果他们使用的是iPad(如使用不同的图像)添加到视图。

I would like to make it so that my iOS applications look good on both iPhone and iPad, and have a separate .xib files for each. 我想这样做,以便我的iOS应用程序在iPhone和iPad上看起来都很好,并且每个应用程序都有一个单独的.xib文件。 Is it possible to change the default .xib file from RootViewController to RootViewController_iPad ? 是否可以将默认的.xib文件从RootViewController更改为RootViewController_iPad

In order to make an application work in both iPhone & iPad then need to follow below steps. 为了使应用程序在iPhone和iPad上都能正常工作,需要按照以下步骤操作。

  1. Before create an project please select universal in device section. 在创建项目之前,请在设备部分选择通用。
  2. In application: didFinishLaunchingWithOptions: put a condition to check the device. 在应用程序中:didFinishLaunchingWithOptions:设置条件来检查设备。
  3. If the device is iPad then load the iPad screen and if the device is iPhone then load the iPhone screen. 如果设备是iPad,则加载iPad屏幕,如果设备是iPhone,则加载iPhone屏幕。
  4. Make sure follow the MVC pattern, So that it is easy to populate the data in both the screens. 确保遵循MVC模式,以便在两个屏幕中轻松填充数据。

@class has no effect on outlets or actions it only tells the compiler that there is a class with the name that follows, no information about properties, or methods is included. @class对出口或操作没有影响它只告诉编译器有一个名称跟随的类,没有包含属性的信息或方法。

If you want to have a xib for the iPad don't create a new class for it, just create a new xib and set the file's owner to be the same as the what owns iPhone xib. 如果你想为iPad安装一个xib,不要为它创建一个新类,只需创建一个新的xib并将文件的所有者设置为与拥有iPhone xib的所有者相同。 You then need to add a check in application: didFinishLaunchingWithOptions: to load the correct xib. 然后,您需要在application: didFinishLaunchingWithOptions:添加一个检查application: didFinishLaunchingWithOptions:以加载正确的xib。

The best option though is to tell Xcode you want a universal app when you create the project. 最好的选择是在创建项目时告诉Xcode你想要一个通用应用程序。

The key point here is that it must be a UNIVERSAL application . 这里的关键点是它必须是一个UNIVERSAL application Its a setting when you set the app up for the 1st time. 当您第一次设置应用程序时,它是一个设置。 You will end up with 2 UI's (story boards or xib files). 最终会得到2个UI(故事板或xib文件)。

You will have to create 2 seperate UI's for ipad and iphone. 您将不得不为ipad和iphone创建2个单独的UI。 You may be able to use the main class itself for most of the code but then you have to basically put code that says 您可以在大多数代码中使用主类本身,但是您必须基本上放置代码

if its iphone.....

if its ipad ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM