iOS: 建立universal app

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

universal project的基本特色:app

1. target > summary > devices is universaliphone

2. xib for ipad and xib for iphone can share the same view controller,固然使用不一樣的view controller絕對沒問題。oop

3. in appdelegate.m didFinishLaunchingWithOptions method, use following code to 根據device是ipad仍是iphone來指定 access 不一樣的 viewui

 

[cpp]  view plain copy
  1.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  2.   
  3.     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {  
  4.         self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];  
  5.     } else {  
  6.         self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];  
  7.     }  
  8.   
  9. <pre name="code" class="cpp">    self.window.rootViewController = self.viewController;</pre> [self.window makeKeyAndVisible];<p></p>  
  10. <pre></pre>  
  11. <br>  
  12. 4. 其餘class還能夠經過<br>  
  13. <p></p>  
  14. <p></p><pre name="code" class="cpp">[[UIDevice currentDevice] userInterfaceIdiom]</pre>來判斷是ipad仍是iphone來執行不一樣的代碼<p></p>  
  15. <p><br>  
  16. </p>  
  17. <p><strong><span style="color:#ff0000">如何把iphone app轉換成universal app?</span></strong></p>  
  18. <p>很是簡單,只須要把target > summary > devices option設置爲universal便可。固然你要本身建立一組for ipad的ui,並在delegate.m里根據device指定不一樣的view。</p>  
  19. <p><br>  
  20. </p>  
  21. <p>ref links:</p>  
  22. <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>  
  23. </p>  
  24. <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>  
  25. </p>  
  26. <p><br>  
  27. </p>  
  28. <p><br>  
  29. </p>  
  30. <div><br>  
  31. </div>  
相關文章
相關標籤/搜索