Failure to use resizableImageWithCapInsets: UIEdgeInsetsMake

Basically, I use resizableImageWithCapInsets: UIEdgeInsetsMake. But I'm not sure that this is the source of my crash. I add these resizable images to the table cell. I am not quite sure how this happens.

Here is the magazine.

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0xa1eab0c4 Crashed Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libobjc.A.dylib 0x3966c5d0 objc_msgSend + 16 1 Foundation 0x3aa1750c probeGC + 60 2 Foundation 0x3aa1d526 -[NSConcreteMapTable removeObjectForKey:] + 30 3 UIKit 0x39e9f46c -[_UIImageViewPretiledImageWrapper dealloc] + 76 4 libobjc.A.dylib 0x3966e490 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 164 5 CoreFoundation 0x3a72882c _CFAutoreleasePoolPop + 12 6 Foundation 0x3aa12e10 -[NSAutoreleasePool release] + 116 7 UIKit 0x39b0f80c -[UITableView layoutSubviews] + 220 8 UIKit 0x39acb892 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 254 9 QuartzCore 0x37fce4e6 -[CALayer layoutSublayers] + 210 10 QuartzCore 0x37fce088 CA::Layer::layout_if_needed(CA::Transaction*) + 456 11 QuartzCore 0x37fcefac CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 12 12 QuartzCore 0x37fce996 CA::Context::commit_transaction(CA::Transaction*) + 234 13 QuartzCore 0x37fce7a8 CA::Transaction::commit() + 312 14 QuartzCore 0x37fce60c CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56 15 CoreFoundation 0x3a7ba93e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18 16 CoreFoundation 0x3a7b8c34 __CFRunLoopDoObservers + 272 17 CoreFoundation 0x3a7b8f8e __CFRunLoopRun + 742 18 CoreFoundation 0x3a72c238 CFRunLoopRunSpecific + 352 19 CoreFoundation 0x3a72c0c4 CFRunLoopRunInMode + 100 20 GraphicsServices 0x37a65336 GSEventRunModal + 70 21 UIKit 0x39b1c28c UIApplicationMain + 1116 
0
source share
2 answers

I had the same problem, this only happened with devices with iOS5.x, resizing the UIImageView, which duplicates the UIImage created in this way:

  UIEdgeInsets edgeInsets = UIEdgeInsetsMake(topCapHeight, leftCapWidth, topCapHeight, leftCapWidth); image = [originalImage resizableImageWithCapInsets:edgeInsets]; 

this is probably an iOS bug fixed in iOS6.x

If your case resizes the image using mirror criteria, you can use this method:

create a UIImage category and add this instance method:

 - (UIImage*)resizableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight </b> { UIImage *image = nil; float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; if (osVersion < 6.0) { image = [self stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight]; } else { UIEdgeInsets edgeInsets = UIEdgeInsetsMake(topCapHeight, leftCapWidth, topCapHeight, leftCapWidth); image = [self resizableImageWithCapInsets:edgeInsets]; } return image; } 

method: - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

deprecated in the iOS documentation, but not in the structure, this means that you can use it when launching the application on a device with iOS5.x without any problems, and the user is a new supported method with devices with iOS 6 or higher.

+2
source

Just FYI.

I also had a crash similar to this, and the fix was actually not in the code, but in the asset itself.

According to Apple Documentation, the scope of the asset should be 1px by 1px, so ensure that it exists.

- (UIImage *) resizableImageWithCapInsets: (UIEdgeInsets) capInsets

When scaling or resizing an image, the areas covered by the cap do not scale or change. Instead, the pixel area that is not covered by a cap in each direction is tiled, from left to right and from top to bottom, to resize the image. This method is often used to create variable-width buttons that retain the same rounded corners, but whose center area grows or shrinks as needed. For maximum performance, use a tile area of ​​1x1 pixels.

0
source

Source: https://habr.com/ru/post/1434075/


All Articles