简体   繁体   English

我如何加入iPad和iPhone应用程序?

[英]How can i join an iPad and iPhone app?

I have an iPad app and an iPhone app. 我有一个iPad应用程序和一个iPhone应用程序。

I would like to join them so that if the join app will run on the iPad it would have a behaviour and if it runs on the iPhone it will have another. 我想加入他们,以便如果加入应用程序将在iPad上运行它将有一个行为,如果它在iPhone上运行它将有另一个。

The first thing that i thought was to make different views and select the view for the iphone/ipad but i also have some things specific to the ipad and iphone (example : splitViewController) so only selecting a different view won't help. 我想的第一件事就是制作不同的视图并选择iphone / ipad的视图,但我也有一些特定于ipad和iphone的东西(例如:splitViewController),所以只选择不同的视图无济于事。

What is the best way to join 2 such apps ? 加入2个这样的应用程序的最佳方式是什么? i would like a more elegant method than doing something like 我想要一种比做类似的更优雅的方法

if(isIPhone)
{
// code for iphone

}
else if(isIPad)
{
// code for iPad

}

every time i have a difference between the 2 versions. 每次我有两个版本之间的差异。 Thanks! 谢谢!

I believe that the WWDC 2010 session videos include an iPad Development Overview that covers exactly this issue. 我相信WWDC 2010会议视频包含一个涵盖此问题的iPad开发概述。

Here's the approach I've taken, according to Apple's guidance: 根据Apple的指导,这是我采取的方法:

You can set platform-specific Main Interface nibs, which means you can set platform-specific app delegates as well. 您可以设置特定于平台的主界面笔尖,这意味着您也可以设置特定于平台的应用程序委托 So you perhaps have a superclass app delegate that does all your app setup, then subclasses to deploy either an iPad UI or an iPhone UI. 因此,您可能拥有一个超级应用程序委托,它可以完成您的所有应用程序设置,然后是子类来部署iPad UI或iPhone UI。

This is helpful since, on the iPad, split views need a traffic cop to determine what content goes where. 这很有用,因为在iPad上,拆分视图需要交通警察来确定哪些内容在哪里。 Now you've got a spot to put that logic independent of the view controllers: in the app delegate. 现在你有一个位置可以将该逻辑独立于视图控制器:在app delegate中。

From there, any time there is a view controller that is common to both platforms but has some specific behavior for each, a view controller superclass is created that handles all common functionality. 从那里,只要有一个视图控制器对两个平台都是通用的,但每个平台都有一些特定的行为,就会创建一个处理所有常用功能的视图控制器超类。 An iPad-specific subclass might then override the -refreshView: method to do some additional animation, or to add properties and delegate methods to support split views. 然后,特定于iPad的子类可以覆盖-refreshView:方法以执行一些额外的动画,或者添加属性和委托方法以支持拆分视图。

While you can definitely test for iPad-ness with if else , this can get really gnarly in a view controller as you add delegate methods that only matter on one platform. 虽然你绝对可以使用if else测试iPad-ness,但是当你添加仅在一个平台上重要的委托方法时,这在视图控制器中会变得非常粗糙。 By splitting it up this way, you get code that's a lot easier to maintain and read. 通过这种方式将其拆分,您可以获得更易于维护和读取的代码。 This can all mean a lot of refactoring of an existing project. 这可能意味着对现有项目进行大量重构。 In my case, though, it only took about an hour and the result is a very tidy app that's easy to jump in and modify for one or both platforms. 在我的情况下,它只花了大约一个小时,结果是一个非常整洁的应用程序,很容易跳入并修改一个或两个平台。

What you are looking for is this: 你在寻找的是:

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    // Do iPad specific stuff.
} else {
    // Do iPhone/iPod touch stuff here.
}

In XCode 4 at least, you can set which code you want each target to compile, and ignore the rest entirely. 至少在XCode 4中,您可以设置希望每个目标编译的代码,并完全忽略其余代码。 So in theory, you could copy all of your iPad app into the iPhone app and then make sure that each only references its own resources and code. 因此,理论上,您可以将所有iPad应用程序复制到iPhone应用程序中,然后确保每个应用程序仅引用自己的资源和代码。 The only issue you might run into is naming conflicts, but you can get around this by using groups and folders. 您可能遇到的唯一问题是命名冲突,但您可以通过使用组和文件夹解决此问题。

That seems like the simplest way, since you already have both built. 这似乎是最简单的方法,因为你已经建成了。 The disadvantage with this method is that you will still have to fix bugs in the code separately, but your users will be able to use the same app on their iPhone and iPad. 这种方法的缺点是你仍然需要单独修复代码中的错误,但你的用户将能够在他们的iPhone和iPad上使用相同的应用程序。

EDIT: 编辑:

See BUILD_PHASES > COPY_BUNDLE_RESOURCES & BUILD_PHASES > COMPILE SOURCES 请参见BUILD_PHASES > COPY_BUNDLE_RESOURCES & BUILD_PHASES > COMPILE SOURCES

Can't you just join the files together in one app? 你不能只在一个应用程序中加入文件吗? Like you copy all the source files from the ipad app to the iphones app project (you may have to rename sonme, so there are no duplicate ones)... then in your app delegate you have one if else switch determining whether on ipad and or iphone which adds the required files 就像你将所有源文件从ipad应用程序复制到iphone应用程序项目(你可能必须重命名sonme,所以没有重复的那些)...然后在你的app委托你有一个if if切换确定是否在ipad和或iphone添加所需的文件

This is especially suitable when using an UITabbarcontroller, as you can simply set up the controller with either the rootviews for ipad or for iphone... 这在使用UITabbarcontroller时特别适合,因为您可以使用ipad或iphone的rootviews设置控制器...

All the other source files remain the same (except for renaming mentioned above)... Will increase the file size very much though, i guess.. 所有其他源文件保持不变(除了上面提到的重命名)...虽然会增加文件大小,我猜...

SideSwipe 侧击

you could probably try turning it into a universal app in xCode 4. Here is a link to a short intro that got me on my way to building a universal app. 您可以尝试将其转换为xCode 4中的通用应用程序。这是一个简短介绍的链接,让我开始构建通用应用程序。

Universal Apps 通用应用

Its very simple. 它非常简单。

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

    // Do iPad stuff

    } else {

    // Do iPhone stuff

    }

But be carefull while loading the nib names inside the conditions. 但是在条件中加载笔尖名称时要小心。 Hope you know that you have to design the .xib for iPad and iPhone separately. 希望你知道你必须分别为iPad和iPhone设计.xib。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式确定我的应用程序是iPad还是iPhone - How can I programmatically determine if my app iPad or iPhone 如何将iPhone / iPad应用程序与iBooks上的电子书捆绑在一起? - How can I bundle an iPhone/iPad app with an ebook on iBooks? 如何从现有的 iPhone 代码库发布 iPad 应用程序? - How can I publish an iPad app from an existing iPhone codebase? 如何为iPhone / iPad应用程序创建浮动工具栏? - How can I create a floating toolbar for an iPhone/iPad app? 如何以编程方式确定我的应用程序正在iPhone,iPad或iPhone 4上运行? - How can I determine programmatically that my app is running on an iPhone, iPad or iPhone 4? 如何在iPhone / iPad中解除pushViewController? - How can I dismiss a pushViewController in iPhone/iPad? 如何在ipad应用程序中添加iphone界面,以便在应用程序启动时选择正确的界面? - How can i add an iphone interface to a ipad app so that the proper interface is selected when the app is started? 如果我使用iPad尺寸创建应用,如何找到iPhone尺寸的“安全区域”? - How can I find the 'safe region' for iPhone size if I am creating my app using iPad size? 我可以缩放我的iPAD应用程序以使其自动适合iPhone吗 - Can I scale my iPAD app to fit on a iphone automatically 我可以在iPad上为iPhone定位的应用安装临时构建吗? - Can I install an ad hoc build on iPad for an iPhone targeted app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM