universal app supports both ipad and iphone。要了解universal如何支援both ipad and iphone,最直接的方法就是建立一個universal project。
universal project的基本特點:
1. target > summary > devices is universal
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnL0AzMx81N4UDO4czNzMTMvw1My8CX1AjMxAjMvw1ckF2bsBXdvwFdl5mLuR2cj5Set1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
2. xib for ipad and xib for iphone can share the same view controller,當然使用不同的view controller絕對沒問題。
3. in appdelegate.m didFinishLaunchingWithOptions method, use following code to 根據device是ipad還是iphone來指定 access 不同的 view
[cpp] view plain copy
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
- } else {
- self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
- }
- <pre name="code" class="cpp"> self.window.rootViewController = self.viewController;</pre> [self.window makeKeyAndVisible];<p></p>
- <pre></pre>
- <br>
- 4. 其他class還可以通過<br>
- <p></p>
- <p></p><pre name="code" class="cpp">[[UIDevice currentDevice] userInterfaceIdiom]</pre>來判斷是ipad還是iphone來執行不同的代碼<p></p>
- <p><br>
- </p>
- <p><strong><span style="color:#ff0000">如何把iphone app轉換成universal app?</span></strong></p>
- <p>非常簡單,隻需要把target > summary > devices option設定為universal即可。當然你要自己建立一組for ipad的ui,并在delegate.m裡根據device指定不同的view。</p>
- <p><br>
- </p>
- <p>ref links:</p>
- <p><a href="http://richielin-programer.blogspot.com/2010/06/iphone-ipad-universal-app.html">http://richielin-programer.blogspot.com/2010/06/iphone-ipad-universal-app.html</a><br>
- </p>
- <p><a href="http://iphonedevelopment.blogspot.com/2010/04/converting-iphone-apps-to-universal.html">http://iphonedevelopment.blogspot.com/2010/04/converting-iphone-apps-to-universal.html</a><br>
- </p>
- <p><br>
- </p>
- <p><br>
- </p>
- <div><br>
- </div>