WidgetKit中accessoryInline组件无法显示图片的技术求助
我开发了一个适配iPhone锁屏和Watch复杂功能的accessoryInline小组件,希望在其中显示一张带透明通道的彩色PNG图片(同时兼容iOS和watchOS)。图片尺寸约80x80,我了解Widget中使用Image存在一些限制,但此图片尺寸很小。
该图片在accessoryCircular组件中可以正常显示,但在accessoryInline中仅显示为一个白色圆角圆圈(能看出图片的形状但被完全填充为白色)。控制台日志中出现以下错误:
CreateWithURL:342: *** ERROR: err=2 (No such file or directory) - could not open '<CFURL 0x10d41bdd0 [0x1d68eee30]>{string = file:///Users/xxx/Library/Developer/CoreSimulator/Devices/xx/data/Library/Caches/com.apple.chrono/snapshot-cache/xx/xx/accessoryInline---1654250760779651625--0.00w-0.00h-0.00r-wzhHcFr6+p3NmSKXbbQN9MPW+BRELiEa9sac7+yu0n8=----0.dark.private-exception.snapshot, encoding = 134217984, base = (null)}'
createImageAtIndex:1955: *** ERROR: could not find plugin for image source - imageRead is NULL
我确认图片存在,因为它在accessoryCircular中可以正常渲染。尝试过多种方法,比如使用UIImage或CGImage加载图片,也用CGContext.makeImage调整过图片尺寸,但均无效。注:我没有可用的真实设备,无法在真机上测试。
附上图片:
内容的提问来源于stack exchange,提问作者Vincent

