iOS 项目中的 Xamarin Studio 文件夹结构问题 [英] Xamarin studio folder structure issue in iOS project

查看:32
本文介绍了iOS 项目中的 Xamarin Studio 文件夹结构问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 xamarin 文件夹时遇到问题.目前我正在编写 xamarin iOS 项目.在 Xcode 中,我使用目录对图像进行分组,可能有多个级别的嵌套文件夹,但是当我为设备或 iOS 模拟器构建项目时,这些资源只是被复制到主包中,没有任何文件夹结构.我无法在 xamarin 工作室中达到相同的行为.每当我在项目中创建文件夹并将图片或其他资源放入其中时,就会在实际设备上重新创建此文件夹结构,因此,在加载图像时,我会遇到不同的路径.如何让 xamarin studio 简单地将文件夹中的文件复制到主包,而不是重新创建文件夹结构?

I am having trouble with xamarin folders. Currently I'm writing xamarin iOS project. In Xcode I used directories for grouping images, there could be several levels of nested folders, but when I was building project for device or iOS simulator, these resources where simply being copied to main bundle, without any folder structure. I can't reach the same behaviour in xamarin studio. Whenever I create folders in my project and put pictures or other resources in them, this folder structure is recreated on the actual device, and thus, I struggle against different paths, when loading images. How can I make xamarin studio simply copy the files in the folders to main bundle, instead of recreating folder structure?

感谢您的帮助.

推荐答案

我的第一个建议是将图像的 BuildAction 属性更改为 BundleResource.

My first suggestion is to change the BuildAction property of your images to BundleResource.

一旦您这样做,就有多种方法可以实现您的目标:

Once you do that, there are multiple ways of achieving your goal:

第一个选项是将 LogicalName 指定为您希望在编译的应用程序包中包含的任何名称.目前没有办法为 EmbeddedResource 文件以外的任何内容设置 Resource ID(LogicalName 属性的 UI 名称)(我将立即修复该问题),但是您可以像这样编辑 *.csproj:

The first option is to specify a LogicalName to be whatever you want the name to be inside of the compiled app bundle. Currently there's no way to set the Resource ID (UI name for the LogicalName property) for anything other than EmbeddedResource files (I'll work on fixing that momentarily), but you can edit the *.csproj like so:

<BundleResource Include="Icons\icon.png">
  <LogicalName>icon.png</LogicalName>
</BundleResource>

通常,Icons\icon.png 文件将作为 Icons/icon.png 复制到 iOS 应用程序包中,但是,LogicalName 属性会覆盖相对路径姓名.在这种情况下,它会被简单地复制为 icon.png.

Normally, that Icons\icon.png file would be copied into the iOS app bundle as Icons/icon.png, however, the LogicalName property overrides the relative path name. In this case it would be copied over as simply icon.png.

再举一个例子,你也可以这样做:

As another example, you can also do this:

<BundleResource Include="Icons\iOS\icon.png">
  <LogicalName>AppIcon.png</LogicalName>
</BundleResource>

这会将 Icons\iOS\icon.png 文件复制到 iOS 应用程序包的根目录中,并将其重命名为 AppIcon.png.

This will copy the Icons\iOS\icon.png file into the root of the iOS app bundle and also rename it to AppIcon.png.

第二个选项是简单地将您的图像文件移动到 Resources 文件夹中.Resources 文件夹是一个特殊的目录,当复制到 iOS 应用程序包时,它会从默认路径名中剥离出来.换句话说,Resources\icon.png 将作为 icon.png 而不是 Resources\icon.png<复制到 iOS 应用程序包的根目录中/code> 与普通项目目录一样.

A second option is to simply move your image file(s) into the Resources folder. The Resources folder is special directory that get stripped out of the default path names when copied over to the iOS app bundle. In other words, Resources\icon.png would be copied over into the root of the iOS app bundle as icon.png rather than Resources\icon.png as is the case with normal project directories.

第三种选择是简单地注册您自己的其他Resource"目录(它们可以存在于其他目录中,包括默认的 Resources 目录).

A third option is to simply register other "Resource" directories of your own (and they can exist within other directories, including the default Resources directory).

例如,您可以在项目中具有以下结构:

For example, you could have the structure in your project:

Resources/
   Icons/
      icon.png
      icon@2x.png

在您的 *.csproj 文件中,编辑以下标签:

And in your *.csproj file, edit the following tag:

<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>

并将其替换为:

<IPhoneResourcePrefix>Resources;Resources\Icons</IPhoneResourcePrefix>

这将确保 icon.png 和 icon@2x.png 文件安装在 iOS 应用程序包的根目录中.

This will ensure that the icon.png and icon@2x.png files are installed in the root of the iOS app bundle.

这篇关于iOS 项目中的 Xamarin Studio 文件夹结构问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆