什么是适用于iOS和Mac OS X的跨平台方法?

时间:2022-10-31 12:09:54

There seem to be lots of answers for cross-platform frameworks for devices (iPhone + Android), and cross-platform frameworks for desktops (Mac + Win + Linux). This is a different question regarding a suitable framework, methodology, template app, tutorial, or just helpful hints, on developing native apps (not just web apps) that are cross-platform portable between a device OS and a desktop OS.

对于设备的跨平台框架(iPhone + Android),以及桌面的跨平台框架(Mac + Win + Linux),似乎有很多答案。这是一个不同的问题,关于一个合适的框架、方法、模板应用程序、教程,或者仅仅是有用的提示,关于开发在设备操作系统和桌面操作系统之间可移植的本地应用程序(不仅仅是web应用程序)。

I want to write a app that can run on both my iPhone (or iPad) and also be compiled to run natively on Mac OS X (and not just run in the Simulator). I am willing to live with only basic UI elements that are common to both platforms (only 1 window, generic buttons, textfields, etc.)

我想写一个既可以在我的iPhone(或iPad)上运行又可以在Mac OS X上本地运行的应用程序(而不仅仅是在模拟器上运行)。我愿意只使用两种平台都通用的基本UI元素(只有一个窗口、通用按钮、textfields等)。

What's the best methodology to build a pair of apps, with the minimum number of #ifdef's and other platform specific code rewrites, that will run on my iPhone and natively on my MacBook?

用最少的#ifdef和其他平台特定代码重写两款应用程序,并在我的iPhone上运行,在我的MacBook上运行,构建这两款应用程序的最佳方法是什么?

2 个解决方案

#1


3  

There is no easy way to do this using standard UI controls. AppKit and UIKit are completely different animals. Even the basic UIView and NSView are very different in structure and function. At that level, you won't see anything that could be made cross-platform.

使用标准的UI控件是不容易做到这一点的。AppKit和UIKit是完全不同的动物。甚至基本的UIView和NSView在结构和功能上都有很大的不同。在这个级别上,您不会看到任何可以跨平台的东西。

However, there are display elements that can be made to work on Mac and iOS with minimal changes. Core Animation CALayers are one such element, in that they are the same on Mac OS X and iOS. This is why we chose to use them as the basis for the Core Plot framework, which uses an almost identical codebase to display graphs on Mac and iOS. There are a few platform-specific things to tweak (like the inverted coordinate system a UIView applies to its backing layer), but most of the code will translate to both platforms.

然而,有一些显示元素可以在Mac和iOS上以最小的更改工作。Core Animation CALayers就是这样一个元素,在Mac OS X和iOS上都是一样的。这就是为什么我们选择使用它们作为Core Plot框架的基础,该框架使用几乎相同的代码基在Mac和iOS上显示图形。有一些特定于平台的东西需要调整(比如一个UIView应用于它的支持层的反向坐标系统),但是大部分代码将转换到两个平台。

You mention writing a game. If you are using OpenGL ES for this, much of the rendering code you write will also work on the Mac. There are a few things you will need to alter, but for the most part OpenGL ES is a subset of desktop OpenGL. However, for a simple 2-D game I'd recommend sticking with Core Animation unless you really hit a brick wall, performance-wise, simply because you will write so much less code.

你提到写游戏。如果您正在使用OpenGL ES,那么您编写的大部分呈现代码也将在Mac上工作。然而,对于一个简单的2d游戏,我建议坚持使用Core Animation,除非您真的碰到了性能瓶颈,因为您将编写更少的代码。

The items I've mentioned so far have all been in the View portion of the Model-View-Controller design pattern. Your controller code will be application-specific, but you may be able to make most of that platform-independent. If you use a simple model, or even one that relies on SQLite or Core Data for persistence, that should be trivial to make work on Mac and iOS with the same code.

到目前为止,我提到的所有项目都位于模型-视图-控制器设计模式的视图部分。您的控制器代码将是特定于应用程序的,但是您可能能够使大多数平*立。如果您使用一个简单的模型,甚至是依赖于SQLite或核心数据的持久性,那么使用相同的代码在Mac和iOS上工作应该是微不足道的。

A Mac application and an iOS one (even between the various iOS devices) will have a very different core design. You can't just shoehorn something from one platform into another. Games are probably more portable than anything else, but you will still need to do some custom work to reflect the unique attributes of each computing device.

Mac应用程序和iOS应用程序(甚至在各种iOS设备之间)的核心设计都将大不相同。你不能把东西从一个平台硬塞到另一个平台。游戏可能比其他任何东西都更便携,但是您仍然需要做一些定制工作来反映每个计算设备的独特属性。

#2


1  

I'm also struggling with this one; I'm using Unity3D and the free license doesn't allow native OS X plug-ins.

我也在和这个做斗争;我正在使用Unity3D软件,免费许可证不允许本地OS X插件。

I've just spent the last hour reading through http://rayvinly.com/how-to-build-a-truly-universal-framework-for-ios-and-mac-with-just-a-single-codebase/

我刚刚花了最后一个小时阅读http://rayvinly.com/how- build-a-truly- universal-frameworkfor - io&mac -with-just-a-single-codebase/

Ray has done a super presentation, you can download his 30 page ebook document! He also provides a template project.

雷做了一个超级演示,你可以下载他的30页电子书文件!他还提供了一个模板项目。

I'm thinking I could use this setup to create a single drawing surface (so, a single window on both platforms) which I could draw to using SpriteKit.

我想我可以使用这个设置来创建一个单独的绘图表面(因此,两个平台上的一个窗口),我可以使用SpriteKit来绘制。

Then wrap mouse/touch input to create a unified input.

然后用鼠标/触摸输入来创建一个统一的输入。

As for ready-made frameworks, http://chameleonproject.org/ looks interesting.

至于现成的框架,http://chameleonproject.org/看起来很有趣。

http://kivy.org/#home looks much more interesting: multiplatform Python wrapping GLES2

http://kivy.org/#home看起来更有趣:多平台Python包装GLES2

Also http://polycode.org/ http://qt-project.org/

同时http://polycode.org/ http://qt-project.org/

What did you choose in the end?

最后你选择了什么?

#1


3  

There is no easy way to do this using standard UI controls. AppKit and UIKit are completely different animals. Even the basic UIView and NSView are very different in structure and function. At that level, you won't see anything that could be made cross-platform.

使用标准的UI控件是不容易做到这一点的。AppKit和UIKit是完全不同的动物。甚至基本的UIView和NSView在结构和功能上都有很大的不同。在这个级别上,您不会看到任何可以跨平台的东西。

However, there are display elements that can be made to work on Mac and iOS with minimal changes. Core Animation CALayers are one such element, in that they are the same on Mac OS X and iOS. This is why we chose to use them as the basis for the Core Plot framework, which uses an almost identical codebase to display graphs on Mac and iOS. There are a few platform-specific things to tweak (like the inverted coordinate system a UIView applies to its backing layer), but most of the code will translate to both platforms.

然而,有一些显示元素可以在Mac和iOS上以最小的更改工作。Core Animation CALayers就是这样一个元素,在Mac OS X和iOS上都是一样的。这就是为什么我们选择使用它们作为Core Plot框架的基础,该框架使用几乎相同的代码基在Mac和iOS上显示图形。有一些特定于平台的东西需要调整(比如一个UIView应用于它的支持层的反向坐标系统),但是大部分代码将转换到两个平台。

You mention writing a game. If you are using OpenGL ES for this, much of the rendering code you write will also work on the Mac. There are a few things you will need to alter, but for the most part OpenGL ES is a subset of desktop OpenGL. However, for a simple 2-D game I'd recommend sticking with Core Animation unless you really hit a brick wall, performance-wise, simply because you will write so much less code.

你提到写游戏。如果您正在使用OpenGL ES,那么您编写的大部分呈现代码也将在Mac上工作。然而,对于一个简单的2d游戏,我建议坚持使用Core Animation,除非您真的碰到了性能瓶颈,因为您将编写更少的代码。

The items I've mentioned so far have all been in the View portion of the Model-View-Controller design pattern. Your controller code will be application-specific, but you may be able to make most of that platform-independent. If you use a simple model, or even one that relies on SQLite or Core Data for persistence, that should be trivial to make work on Mac and iOS with the same code.

到目前为止,我提到的所有项目都位于模型-视图-控制器设计模式的视图部分。您的控制器代码将是特定于应用程序的,但是您可能能够使大多数平*立。如果您使用一个简单的模型,甚至是依赖于SQLite或核心数据的持久性,那么使用相同的代码在Mac和iOS上工作应该是微不足道的。

A Mac application and an iOS one (even between the various iOS devices) will have a very different core design. You can't just shoehorn something from one platform into another. Games are probably more portable than anything else, but you will still need to do some custom work to reflect the unique attributes of each computing device.

Mac应用程序和iOS应用程序(甚至在各种iOS设备之间)的核心设计都将大不相同。你不能把东西从一个平台硬塞到另一个平台。游戏可能比其他任何东西都更便携,但是您仍然需要做一些定制工作来反映每个计算设备的独特属性。

#2


1  

I'm also struggling with this one; I'm using Unity3D and the free license doesn't allow native OS X plug-ins.

我也在和这个做斗争;我正在使用Unity3D软件,免费许可证不允许本地OS X插件。

I've just spent the last hour reading through http://rayvinly.com/how-to-build-a-truly-universal-framework-for-ios-and-mac-with-just-a-single-codebase/

我刚刚花了最后一个小时阅读http://rayvinly.com/how- build-a-truly- universal-frameworkfor - io&mac -with-just-a-single-codebase/

Ray has done a super presentation, you can download his 30 page ebook document! He also provides a template project.

雷做了一个超级演示,你可以下载他的30页电子书文件!他还提供了一个模板项目。

I'm thinking I could use this setup to create a single drawing surface (so, a single window on both platforms) which I could draw to using SpriteKit.

我想我可以使用这个设置来创建一个单独的绘图表面(因此,两个平台上的一个窗口),我可以使用SpriteKit来绘制。

Then wrap mouse/touch input to create a unified input.

然后用鼠标/触摸输入来创建一个统一的输入。

As for ready-made frameworks, http://chameleonproject.org/ looks interesting.

至于现成的框架,http://chameleonproject.org/看起来很有趣。

http://kivy.org/#home looks much more interesting: multiplatform Python wrapping GLES2

http://kivy.org/#home看起来更有趣:多平台Python包装GLES2

Also http://polycode.org/ http://qt-project.org/

同时http://polycode.org/ http://qt-project.org/

What did you choose in the end?

最后你选择了什么?