天天看點

iOS: 建立universal app

universal app supports both ipad and iphone。要了解universal如何支援both ipad and iphone,最直接的方法就是建立一個universal project。

universal project的基本特點:

1. target > summary > devices is universal

iOS: 建立universal app

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

  1.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  2.     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {  
  3.         self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];  
  4.     } else {  
  5.         self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];  
  6.     }  
  7. <pre name="code" class="cpp">    self.window.rootViewController = self.viewController;</pre> [self.window makeKeyAndVisible];<p></p>  
  8. <pre></pre>  
  9. <br>  
  10. 4. 其他class還可以通過<br>  
  11. <p></p>  
  12. <p></p><pre name="code" class="cpp">[[UIDevice currentDevice] userInterfaceIdiom]</pre>來判斷是ipad還是iphone來執行不同的代碼<p></p>  
  13. <p><br>  
  14. </p>  
  15. <p><strong><span style="color:#ff0000">如何把iphone app轉換成universal app?</span></strong></p>  
  16. <p>非常簡單,隻需要把target > summary > devices option設定為universal即可。當然你要自己建立一組for ipad的ui,并在delegate.m裡根據device指定不同的view。</p>  
  17. <p><br>  
  18. </p>  
  19. <p>ref links:</p>  
  20. <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>  
  21. </p>  
  22. <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>  
  23. </p>  
  24. <p><br>  
  25. </p>  
  26. <p><br>  
  27. </p>  
  28. <div><br>  
  29. </div>  

繼續閱讀