之前文章有讲过Images.xcassets图片拉伸,可以对图片进行局部拉伸。
从iOS 7到现在,也一直这么使用的,在iOS 17上运行时出现了问题。
图片是22×2像素的矩形图片,我对图片进行了拉伸设置
Slicing在iOS 17.1和iOS 17.2上运行时,图片不显示
在iOS 17.0上运行时(iOS 17.0.2、iOS 17.0.3),闪退,报错如下:
*** Assertion failure in void _UIGraphicsBeginImageContextWithOptions (CGSize, BOOL, CGFloat,
BOOL) (), UIGraphics.m:410
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={66, nan}, scale=2.000000, bitmapInfo=0×2002. Use UIGraphicsImageRenderer to avoid this assert.'
*** First throw call stack:
(0x1b309e5e0 0x1ab3d3c00 0x1b2608404 0x1b52b88b0 0x1b52b687c 0x1b51dedd4 0x151dd148 0x1b5225aec
0x1b5225564 0x1b2fe6d94 0x1b2fe6b30 0x1b51dd7cc 0x1b520133c 0x1b51f8464 0x1b51f8a6c 0x1b51f7184
0x1b460f888 0x1b51fa250 0x1b5206218 0x1b544e1f0 0x1b544da70 0x1b544bfbc 0x1b544baa4 0x1b51f7184
0x1b460f888 0x1b460f410 0x1b461594c 0x1b460ec3c 0x1b460e8e4 0x1b526f228 0x1b526ed40 0x1b526e430
0x1b526e4ec 0x1b2fe8acc 0x1b2fe7d48 0x1b2fe64fc 0x1b2fe5238 0x1b2fe4e18 0x1f5aa95ec 0x1b53f32fc
0x1b53f2938 0x1009fd28c 0x1d57cfd44)
libc++abi: terminating due to uncaught exception of type NSException
其他图片拉伸则没有这个问题
根据查阅的资料,iOS 17上使用UIGraphicsBeginImageContext()
,size
为0时,就会报相同的错误。
我估计我这个问题应该是top
和bottom
设置为0的原因,内部也是通过UIGraphicsBeginImageContext()
实现的。
具体可参考:
iOS-bug,Xcode,iOS17,“UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}
ReactNative中升级IOS 17版本Crash解决
网友评论