注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

我的博客

 
 
 

日志

 
 

【引用】如何将ipone项目转到ipad平台  

2011-09-06 10:36:02|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
这篇文章很详细地为我们讲解了如何将让之前的ipone项目在ipad上运行,感觉很不错,遂与大家分享,比较容易读懂,就不翻译了!:)
刚发现本文的作者是Wei-Meng Lee,感谢同胞的不吝分享!

原贴自:http://www.devx.com/wireless/Article/44472
Now that Apple has started selling the iPad and the NDA lifted on the iPhone 3.2 SDK, it is time for developers to start developing iPad applications. And for a large number of developers, developing iPad applications mean porting their existing applications to the iPad platform. Though the iPad is also running the iPhone OS, there are some subtle differences that developers need to look out for when porting their applications over to the new device. This article examines the various ways in which you can port your existing iPhone apps to the iPad.

Method 1: Supporting Both the iPhone and iPad Platforms
Out of the box, the iPad will run your existing iPhone apps using the same screen size that is available on the iPhone and iPod touch -- 320 x 480 pixels. Your applications will utilize only a portion of the screen. However, applications running in this mode do not do justice to the much bigger screen estate afforded by the iPad. Clearly, this is an interim solution that Apple is adopting in order to buy time for developers to port their applications UI to the much bigger iPad screen.
The easiest way for you to ensure that your iPhone applications run as an iPad application (that is, full screen) is to modify the device target setting in your Xcode application. The following steps show you how.

Using Xcode, create a new View-based Application (iPhone) project (see Figure 1).

如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 1. Creating a View-based Application for iPhone.
Name the project MyiPhoneApp. Double-click on the MyiPhoneAppViewController.xib file to edit it in Interface Builder. Populate the View window with the following views (see also Figure 2):
* Label
* TextField
* Button

如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 2. Populating the View window with views.
Back in Xcode, press Command-R to test the application on the iPhone Simulator. You should see the screen as shown in Figure 3.


如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 3. Running the application on the iPhone Simulator.
In Xcode, change the simulator to Simulator - 3.2 | Debug and press Command-R again. This time, the application will be shown running in the iPad Simulator, running as an iPhone application (see Figure 4). This is the default behavior of iPhone applications running on the iPad.


如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 4. Running the application on the iPad Simulator.
Next, in Xcode, expand on the Targets item and select the MyiPhoneApp item. Click the Info (i) button (located at the top of the toolbar) to display its Info page (see Figure 5). Click on the Build tab and scroll down the list. Under the Deployment section, select "iPhone/iPad" for the Targeted Device Family setting.

如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 5. Changing the Targeted Device Family setting of the project to iPhone/iPad.
Press Command-R to test the application on the simulator again. This time, your application will run natively as an iPad application (see Figure 6).

如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 6. Running the application as an iPad application.
Notice that the UI of the application is exactly the same as that on the iPhone. It is your responsibility to repurpose your UI when the application is running on the iPad. You would need to programmatically realign your views when your application detects that it is running on an iPad.
Detecting the Platform Programmatically

In order to repurpose your UI depending on the device it is running on, it is important to be able to programmatically detect if your application is running as an iPhone/iPod touch or iPad application. The following code shows you how.
In the MyiPhoneAppViewController.m file, code the following:
- (void)viewDidLoad {

    #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)

    NSString *str;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        str = [NSString stringWithString:@"Running as an iPad application"];
    } else {
        str = [NSString stringWithString:
                  @"Running as an iPhone/iPod touch application"];
    }

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Platform"
                                                    message:str
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];    

    #endif    
    
    [super viewDidLoad];
}

The above code includes a conditional compilation directive to indicate that if the application is compiled against the minimum iPhone OS version of 3.2, then it will include a block of code to programmatically detect the type of application it is currently running as.
Press Command-R to test the application on the Simulator. Observe the message displayed as shown in Figure 7.

如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 7. Displaying the platform it is running as.

If you now go back to Xcode and choose the Simulator - 3.1.3 | Debug item and press Command-R again, the iPhone Simulator will appear and there will be no alert displayed. This is because the application will now be compiled with the iPhone OS 3.1.3 target and hence the compiler will omit the block of code enclosed using the #if-#endif block.

Next, back in Xcode select "iPhone" for the Targeted Device Family setting (as shown in the previous section) and choose the Simulator - 3.2 | Debug item. Press Command-R and you will notice that the application now runs on the iPad Simulator as an iPhone application. Figure 8 shows the alert that it will display.

如何将ipone项目转到ipad平台 - 战狼 - 战狼

Figure 8. Running as an iPhone application on the iPad Simulator
  评论这张
 
阅读(28)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018