如何将 iPhone 应用程序移植到 iPad(故事板)

发布于 2024-12-29 12:04:12 字数 557 浏览 1 评论 0原文

我刚刚完成了我的 iPhone 应用程序,我想让它变得通用。我已经读过一些帖子,但它们有点旧(2010 年左右)。

我得到的:

  • 简单的 iPhone 应用程序,最近创建的(iOS 5 - Storyboard),具有三个屏幕。
  • 我的应用程序代表一张带有三张卡片的桌子,您可以翻转它们并触摸它们。用户可以(在第二个屏幕上)输入要在卡片上显示的文本。
  • 当我创建项目时,我选中了“通用”,所以我有两个故事板。此后,我不再做任何与 iPad 相关的事情(除了我使用 UIModalPresentationPageSheet 的“联系支持”电子邮件选项上的一行)。

我想要完成的任务:

  • iPad 上的同一个应用程序:我的应用程序非常简单,我不需要分割视图或详细信息。我只想要相同的对象和布局,但具有更大更好的图形(表格、卡片等)。

我喜欢它,因为它可以进行很棒的入门级迁移。

我不知道从哪里开始。当我运行 iPad 模拟器时,会出现一个白屏,仅此而已。

I just finished my iPhone app and I want to make it Universal. I've read a few posts already but they're a bit old (2010 or so).

What I got:

  • Simple iPhone app, recently created (iOS 5 - Storyboard), with three screens.
  • My app represents a table with three cards that you can flip touching them. The user can input (on the second screen) text to be displayed on the cards.
  • When I created the project I checked "Universal" so I have two Storyboards. After that nothing else I did had to do with iPad (except for a line on my "contact support" email option where I used UIModalPresentationPageSheet).

What I'd like to accomplish:

  • Same app on the iPad: my application is so straightforward I don't have any use for split views or details. I just want the same objects and layout but with bigger and better graphics (table, cards, etc).

I like it because it'd make a great introduction-level migration.

I have no idea where to start. When I run the iPad simulator a white screen comes up and that's it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

朱染 2025-01-05 12:04:12

好了,这就完成了。

与几乎所有事情一样,一旦您知道要做什么,这就会很容易。

我想说,对于像我这样的情况,UI 的变化不会超过尺寸或 (x,y) 坐标,过程可以总结如下:

  1. 复制 iPad Storyboard 上的每个 UI 元素(复制和粘贴将做)并根据需要调整位置和大小
  2. 再次重新连接所有内容。每个按钮、segue(您还必须再次添加 segue 名称)等。
  3. 在代码中验证 UI 受影响的每个位置(例如 x,y 坐标),确定应用程序是否在 iPhone 或 iPad 上运行,并相应地划分代码
  4. 如果您对应用程序有任何本地化,则必须更新 iPad Storyboard 上的新 UI 元素
  5. 选择在模拟器上进行测试的目标并进行尝试

为了确定应用程序在哪个设备上运行时您可以使用以下命令:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    //I'm running on the iPad
} else {
    //I'm running on the iPhone
}

就是这样。同样,在像我这样的简单情况下,代码的重用是绝对的(100%),您必须添加的新代码是最少的(基本上是需要的 IF 语句),并且 UI 元素的复制就像复制和粘贴一样简单。

我希望这对其他人有用,如果您有改进的建议,我们非常欢迎。

Well this is done.

As with almost everything, this is pretty easy once you know what to do.

I'd say that for those cases like mine, where the UI doesn't change in more than sizes or (x,y) coordinates the process could be summarized like this:

  1. Replicate every UI element on the iPad Storyboard (copy and paste will do) and adjust position and size as you see fit
  2. Re-wire everything again. Every button, segue (you'll have to add the segue name again too), etc.
  3. Verify within your code every place where your UI is affected (e.g. x,y coordinates), identify whether the app is running on an iPhone or iPad, and divide your code accordingly
  4. If you have any localization on the application you'll have to update the new UI elements on the iPad Storyboard
  5. Select the target for testing on the simulator and try it out

In order to identify in which device the app is running you can use the following:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    //I'm running on the iPad
} else {
    //I'm running on the iPhone
}

And that's it. Again, in a simple case like mine the reuse of code is absolute (100%), the new code you'll have to add is minimum (basically IF statements where needed), and the UI elements duplication is as easy as copy and paste.

I hope this is useful to someone else and if you have recommendations to improve this they're more than welcomed.

南风起 2025-01-05 12:04:12

在finder中打开Storyboard文件,复制你的iPhone-Storyboard并将其重命名为Main-iPad.storyboard

在xCode中,右键单击storyboard ->; “打开为”-> “源代码”

搜索 targetRuntime="iOS.CocoaTouch" 并将其设置为 targetRuntime="iOS.CocoaTouch.iPad"

现在保存所有内容并重新打开 Xcode -> iPad 故事板包含与 iPhone 文件相同的内容,但一切可能会被打乱,您必须自己安排。

最后,要获得 iPad 格式,请将 MainStoryboard_iPad.storyboard 中的代码从: 更改为

然后转到“StroryBoardEx-Info.plist”文件,搜索“Main nib 文件基本名称 (iPad)”并将其设为“Main-iPad” .故事板”

Open the Storyboard file in finder,Copy your iPhone-Storyboard and rename it Main-iPad.storyboard

Inside xCode, right click on the storyboard -> “open as” -> “Source Code”

Search for targetRuntime="iOS.CocoaTouch"and make it targetRuntime="iOS.CocoaTouch.iPad"

Now save everything and reopen Xcode -> the iPad-Storyboard contains the same as the iPhone-file but everyting could be disarranged you have to arrange it by your self.

Finally to get the iPad format also change the code in the MainStoryboard_iPad.storyboard from: to

Then go to your "StroryBoardEx-Info.plist" file,search for "Main nib file base name (iPad)" and make it "Main-iPad.storyboard"

甩你一脸翔 2025-01-05 12:04:12

如果您只想重复使用 iPhone 故事板,只需转到项目设置即可。在“目标”选项卡“信息”中,有行“主故事板文件基本名称”和“主故事板文件基本名称 (iPad)”。只需编辑 iPad 一个,使其与另一个具有相同的值即可。就我而言,我必须将其编辑为“主故事板文件基本名称(iPad)”,值为“MainStoryboard_iPhone”。

If you just want to reuse your iphone storyboard, just go to your project settings. In TARGETS tab Info, there are rows 'Main storyboard file base name' and 'Main storyboard file base name (iPad)'. Just edit the iPad one to have the same value as the other. In my case I had to edit it as 'Main storyboard file base name (iPad)' with value 'MainStoryboard_iPhone'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文