如何将 iPhone 应用程序移植到 iPad(故事板)
我刚刚完成了我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好了,这就完成了。
与几乎所有事情一样,一旦您知道要做什么,这就会很容易。
我想说,对于像我这样的情况,UI 的变化不会超过尺寸或 (x,y) 坐标,过程可以总结如下:
为了确定应用程序在哪个设备上运行时您可以使用以下命令:
就是这样。同样,在像我这样的简单情况下,代码的重用是绝对的(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:
In order to identify in which device the app is running you can use the following:
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.
在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"
如果您只想重复使用 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'.