gpt4 book ai didi

ios - UIImage 在主包中加载错误图像

转载 作者:行者123 更新时间:2023-11-29 12:03:21 25 4
gpt4 key购买 nike

我有一个主项目包含超过 10 个包。我有两张名为 map_bubble_right_normal 的图片,一张在主包中,另一张在子包 (SCommon.bundle) 中。我写的代码如下:

UIImage *image = [UIImage imageNamed:@"map_bubble_right_normal"];

代码写在AppDelegatedidFinishLaunchingWithOptions中。

我想加载我保存在主包中的图像。但是,从子包(SCommon.bundle)加载图像的代码的结果。

我猜想保存在主包中的图像可能是错误图像(可能是复制问题)。因此,我显示 ipa 内容以查看保存在根目录中的“map_bubble_right_normal”文件。图像是正确的!!!!!

我不知道为什么 imageNamed: 会从子包 (SCommon.bundle) 加载图像。我尝试删除应用程序并重新启动 iPhone,结果是一样的。而且,我试图删除 XCode 的派生数据,并清理项目。图像仍然从子包(SCommon.bundle)加载。

此外,我在 iOS 8 和 iOS 9 设备上测试了这个问题。

目前只能通过改变bundleId(main bundle)的方法暂时解决问题。

我知道UIImage的缓存特性,但我不明白为什么会出现奇怪的一幕。

恳请各位大神帮忙。谢谢~

最佳答案

谢谢大家的回答。我很抱歉误导了我们所有人。

我找到了问题的原因。错误图片不是来自 Assets.car 的子包。问题的原因实际上应该归咎于物理目录中的Image.assert。 CocoaPods 会将所有匹配的“*.assets”复制到 Assets.car。

我在 Apple Developer forum 提出了同样的问题,找到了问题的关键提示。

Cocoapods相关问题Pods copy resource script overrides default xcasset bahaviour .

如果您的 Pod Repo 添加了名称与 *.xcassets 匹配的任何文件夹,Pod_resources.sh 脚本将复制 Pod_Root 中的每个 *.xcassets

Pod_resources.sh关键代码:

if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ]
...
# Find all other xcassets (this unfortunately includes those of path pods and other targets).
OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d)
while read line; do
if [[ $line != "`realpath $PODS_ROOT`*" ]]; then
XCASSET_FILES+=("$line")
fi
...
fi

如果您的 Pod 添加了任何 xcassets 文件,条件 XCASSET_FILES 将得到满足。

关于ios - UIImage 在主包中加载错误图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36008210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com