之前文章有講過(guò)Images.xcassets圖片拉伸量瓜,可以對(duì)圖片進(jìn)行局部拉伸捧搞。
從iOS 7到現(xiàn)在,也一直這么使用的仰坦,在iOS 17上運(yùn)行時(shí)出現(xiàn)了問(wèn)題。
圖片是22×2像素的矩形圖片,我對(duì)圖片進(jìn)行了拉伸設(shè)置
Slicing
在iOS 17.1和iOS 17.2上運(yùn)行時(shí)盼铁,圖片不顯示
在iOS 17.0上運(yùn)行時(shí)(iOS 17.0.2、iOS 17.0.3)尝偎,閃退饶火,報(bào)錯(cuò)如下:
*** 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
其他圖片拉伸則沒(méi)有這個(gè)問(wèn)題
根據(jù)查閱的資料,iOS 17上使用UIGraphicsBeginImageContext()
致扯,size
為0時(shí)肤寝,就會(huì)報(bào)相同的錯(cuò)誤。
我估計(jì)我這個(gè)問(wèn)題應(yīng)該是top
和bottom
設(shè)置為0的原因抖僵,內(nèi)部也是通過(guò)UIGraphicsBeginImageContext()
實(shí)現(xiàn)的鲤看。
具體可參考:
iOS-bug,Xcode裆针,iOS17刨摩,“UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}
ReactNative中升級(jí)IOS 17版本Crash解決