Xib文件如何将iPone项目转到iPad平台

来源:互联网 发布:山长水阔知何处 编辑:程序博客网 时间:2024/05/02 18:55

我自己来回答,查了stack overflow,copy过来,再加上自己的注释:

 Converting iPhone xib to iPad xib? answer:

 I was able to narrow it down to a few things, so here are the steps that worked for me:

 1) Make a copy of the iPhone xib file and add it to your project 

2) Right click the file (in xcode) and Open As > Source Code 

3) The 2nd line should look like: Replace with: 

4) Search for "IBCocoaTouchFramework" and Replace all occurrences with "IBIPadFramework"

 5) Save the file and Open As > Interface Builder - iOS The file might still look like a regular iPhone xib, but for me, 

once I changed the Status Bar to "Black" in the Attributes inspector the rest of the xib just kind of "snapped" into an iPad xib

我照着这个方法做了,虽然view的大小可以修改为iPad full screen,但view里的内容不会自动放大。我还得手工重新布局。

 注意: 1. 一定要最先修改MainWindow.xib,否则,子view超出原来iPhone界面大小的按钮就没反应。

 2. 如果没有搜索到IBCocoaTouchFramework,是因为你原来的开发版本太低了,

请先将属性中的Document Versioning修改一下。我把Deployment改为iOS4.2,Development改为Xcode4.2.再搜就能搜到了。

有多个Xib 文件如何将iPone项目转到iPad平台是本文要介绍的内容,主要是是解决将iPone项目转到iPad平台,如果有多个Xib文件,该怎么办?来看本文如何来解决。

1、首先,不能把问题考虑复杂了,这个转化其实很简单。

2、将iphone版本升级成universal版本, 方法不赘述。

3、在.plist里,应该会有main nib file base name这个key,对应MainWindow,就是iphone程序的入口;

同时会有main nib file base name(iPad)这项,如果没有,就自己建立个,universal版本会多出来这项,选择它就是了),然后需要自己建立个xib文件,来作为iPad入口,比如说MainWindow-iPad

技巧:已经有iPhone版的xib文件, 打开这个xib文件,然后file==>Create iPad version (using autosizing masks), 会自己生成一个iPad版本的 untile.xib的文件,然后另存为你自己的名字的iPad的xib就可以了。然后拖到并加入到你的项目里。

以上是解决程序入口的问题。

4、对于其他的xib文件,比如说AController.xib,

首先,用上面的技巧生成AController-iPad.xib并加入到你的项目里;

然后找到它对应类文件AController.m,

  1. - (void)viewDidLoad
  2. {
  3. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  4. {
  5. [[NSBundlemainBundle] loadNibNamed:@"AController-iPad"owner:selfoptions:nil];
  6. }
  7. else
  8. {
  9. [[NSBundlemainBundle] loadNibNamed:@"AController"owner:selfoptions:nil];
  10. }
  11. [superviewDidLoad];
  12. //your other init code here
  13. }

加入红色部分的code即可,那个loadNibNamed:根据具体的来改。

5、对于内部的其他代码,若iPhone与iPad版本有区别的话,继续用好上面的if 判断语句就可以了。

  1. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2. {
  3. //iPad version code here
  4. }
  5. else
  6. {
  7. //iPhone/touch version code here
  8. }

6、强烈建议写程序时候对于控件位置和大小,别用具体的数字, 而用size.weight, size.height这样的写法,或者单独开个头文件define出去,不然一个一个的改尺寸大小会很郁闷的。

iphone-->iPad的改动,难倒是不难,主要是要细心而已。

暂时只想到这么多了,以后再补充。

小结:有多个Xib 文件如何将iPone项目转到iPad平台的内容介绍完了,希望通过本文的学习能对你有所帮助!


0 0
原创粉丝点击