如何调整iphone应用程序的xib视图以适应xcode中的ipad

时间:2013-08-20 05:48:38

标签: ios objective-c xcode uiview synchronization

我在通用模式下创建了一个简单的计算器应用程序我有两个xib用于iphone,另一个用于ipad。我只在iphone中创建了我的所有视图设计,我的ipad xib是空白的。现在,当我在ipad中部署我的iphone应用程序时,它的大小与iphone相同。我选择了自动调整大小选项。我是否必须在ipad xib中创建相同的iphone视图以获得正确的显示效果,还是有其他方法吗?这就是我的应用程序当前在ipad上显示的方式。我需要全屏模式。 ipad view

编辑:这是iphone xib的示例源代码。我应该如何修改它以适应ipad?

    <?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
    <data>
        <int key="IBDocument.SystemTarget">1280</int>
        <string key="IBDocument.SystemVersion">10K549</string>
        <string key="IBDocument.InterfaceBuilderVersion">1938</string>
        <string key="IBDocument.AppKitVersion">1038.36</string>
        <string key="IBDocument.HIToolboxVersion">461.00</string>
        <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
            <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
            <string key="NS.object.0">933</string>
        </object>
        <array key="IBDocument.IntegratedClassDependencies">
            <string>IBUIView</string>
            <string>IBUIBarButtonItem</string>
            <string>IBProxyObject</string>
            <string>IBUIToolbar</string>
            <string>IBUITextField</string>
            <string>IBUITextView</string>
            <string>IBUITableView</string>
            <string>IBUITableViewCell</string>
            <string>IBUIButton</string>
        </array>
        <array key="IBDocument.PluginDependencies">
            <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
        </array>
        <object class="NSMutableDictionary" key="IBDocument.Metadata">
            <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
            <integer value="1" key="NS.object.0"/>
        </object>
        <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
            <object class="IBProxyObject" id="372490531">
                <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
                <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
            </object>
            <object class="IBProxyObject" id="843779117">
                <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
                <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
            </object>
            <object class="IBUIView" id="774585933">
                <reference key="NSNextResponder"/>
                <int key="NSvFlags">274</int>
                <array class="NSMutableArray" key="NSSubviews">
                    <object class="IBUITextField" id="234836822">
                        <reference key="NSNextResponder" ref="774585933"/>
                        <int key="NSvFlags">292</int>
                        <string key="NSFrame">{{12, 48}, {286, 31}}</string>
                        <reference key="NSSuperview" ref="774585933"/>
                        <reference key="NSNextKeyView" ref="1066176330"/>
                        <bool key="IBUIOpaque">NO</bool>
                        <bool key="IBUIClipsSubviews">YES</bool>
                        <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
                        <int key="IBUIContentVerticalAlignment">0</int>
                        <string key="IBUIText">0</string>
                        <int key="IBUIBorderStyle">3</int>
                        <object class="NSColor" key="IBUITextColor">
                            <int key="NSColorSpace">3</int>
                            <bytes key="NSWhite">MAA</bytes>
                            <object class="NSColorSpace" key="NSCustomColorSpace">
                                <int key="NSID">2</int>
                            </object>
                        </object>
                        <int key="IBUITextAlignment">2</int>
                        <bool key="IBUIAdjustsFontSizeToFit">YES</bool>
                        <float key="IBUIMinimumFontSize">17</float>
                        <object class="IBUITextInputTraits" key="IBUITextInputTraits">
                            <int key="IBUIKeyboardType">4</int>
                            <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
                        </object>
                        <object class="IBUIFontDescription" key="IBUIFontDescription" id="1025764138">
                            <int key="type">1</int>
                            <double key="pointSize">14</double>
                        </object>
                        <object class="NSFont" key="IBUIFont" id="891898266">
                            <string key="NSName">Helvetica</string>
                            <double key="NSSize">14</double>
                            <int key="NSfFlags">16</int>
                        </object>
                    </object>
                    <object class="IBUIButton" id="1066176330">
                        <reference key="NSNextResponder" ref="774585933"/>
                        <int key="NSvFlags">292</int>
                        <string key="NSFrame">{{41, 102}, {50, 50}}</string>
                        <reference key="NSSuperview" ref="774585933"/>
                        <reference key="NSNextKeyView" ref="182110945"/>
                        <bool key="IBUIOpaque">NO</bool>
                        <int key="IBUITag">1</int>
                        <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
                        <int key="IBUIContentHorizontalAlignment">0</int>
                        <int key="IBUIContentVerticalAlignment">0</int>
                        <int key="IBUIButtonType">1</int>
                        <string key="IBUINormalTitle">1</string>
                        <object class="NSColor" key="IBUIHighlightedTitleColor" id="899681977">
                            <int key="NSColorSpace">3</int>
                            <bytes key="NSWhite">MQA</bytes>
                        </object>

                              . 
                              .
                              .
                              .

<dictionary class="NSMutableDictionary" key="flattenedProperties">
                <string key="-1.CustomClassName">ViewController</string>
                <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="-2.CustomClassName">UIResponder</string>
                <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="10.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="101.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="103.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="104.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="105.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="106.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="11.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="111.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="12.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="13.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="14.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="15.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="16.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="17.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <real value="0.0" key="17.IBUIButtonInspectorSelectedStateConfigurationMetadataKey"/>
                <string key="18.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="19.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="20.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="21.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="22.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="23.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="24.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="25.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="36.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="69.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="78.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="82.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="83.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
                <string key="94.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
            </dictionary>
            <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
            <nil key="activeLocalization"/>
            <dictionary class="NSMutableDictionary" key="localizations"/>
            <nil key="sourceID"/>
            <int key="maxID">125</int>
        </object>
        <object class="IBClassDescriber" key="IBDocument.Classes"/>
        <int key="IBDocument.localizationMode">0</int>
        <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
        <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
        <int key="IBDocument.defaultPropertyAccessControl">3</int>
        <string key="IBCocoaTouchPluginVersion">933</string>
    </data>
</archive>

6 个答案:

答案 0 :(得分:1)

右键点击XIB。

选择打开为。

选择源代码。

在其中修改以下内容:

 <object class="NSArray" key="dict.values">
    <bool key="EncodedWithXMLCoder">YES</bool>
    <string>{320, 480}</string>
    <string>{480, 320}</string>
    </object>

为:

<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{768, 1024}</string>
<string>{1024, 768}</string>
</object>

That's it.

答案 1 :(得分:1)

我建议使用AutoLayout。如果您使用iPhone的自动布局进行视图,它在iPad上看起来几乎相同,只是更大。在XIB中,AutoLayout非常简单。 另一种可能性是为iPad布局创建单独的XIB。如果你这样做,只需看看其他答案,这些答案描述了如何轻松地做到这一点。

答案 2 :(得分:0)

是!!!您还必须在其他iPad文件中为Xib创建视图。

答案 3 :(得分:0)

你需要制作两个单独的xib并管理所有按钮,textfiels并在New Xib中添加所有这些...

从iphone xib创建Ipad Xib的方法......

1)首先复制iphone xib并粘贴,只需改变名称~ipad.xib give并将其添加到包中

2)现在你有一个2 xib 1用于iphone,1用于ipad。

3)转到ipad xib右键单击它看到打开为 - &gt;在源代码中打开它,然后你必须找到320,480值搜索源代码中的值并转换为

... 768,1024

就是这样做......

答案 4 :(得分:0)

来自Converting iPhone xib to iPad xib?

参考Jag的回答......他说的是,

我能够将其缩小到几个方面,所以这里有适合我的步骤:

1)制作iPhone xib文件的副本并将其添加到项目中

2)右键单击文件(在xcode中)和Open As&gt;源代码

3)第二行应该如下:

替换为:

4)搜索“IBCocoaTouchFramework”并将所有出现次数替换为“IBIPadFramework”

5)保存文件并打开为&gt; Interface Builder - iOS

该文件可能仍然看起来像普通的iPhone xib,但对我来说,一旦我在“属性”检查器中将状态栏更改为“黑色”,其余的xib就会“抢占”到iPad xib中

编辑:您也可以这样做==&gt; convert iphone App to IPad

1)选择通用选项。

2)将代码从现有的iPhone项目转移到新项目。

3)现在,为iPad制作xib文件,并进行连接(IBOutlets)。

无论您需要特定于平台的功能(例如,适用于iPad的Popover,Split ViewController等),请使用IF语句来处理设备特定功能。

答案 5 :(得分:0)

在iPhone xib文件中,将目标从iOS.CocoaTouch更改为iOS.CocoaTouch.iPad,现在如果在界面构建器中打开文件,您将看到iPad的设置。