使用resizableImageWithCapInsets崩溃:UIEdgeInsetsMake [英] Crashing using resizableImageWithCapInsets:UIEdgeInsetsMake
问题描述
基本上,我使用的是resizableImageWithCapInsets:UIEdgeInsetsMake。但我不确定这是否是我崩溃的原因。我正在我的表格单元格上添加这些可调整大小的图像。我不确定这是怎么发生的。
Basically, I am using resizableImageWithCapInsets:UIEdgeInsetsMake. But I am not sure if this is the source of my crash. I am adding these resizable images on my table cell. I am not exactly sure on how this is occuring.
这是日志。
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
推荐答案
我遇到了同样的问题,这只发生在iOS5.x调整大小的设备上该diplay以这种方式创建的一个的UIImage的UIImageView:
I had the same problem, this was happening only with devices with iOS5.x resizing an UIImageView that diplay an UIImage created in this way:
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(topCapHeight, leftCapWidth, topCapHeight, leftCapWidth);
image = [originalImage resizableImageWithCapInsets:edgeInsets];
这可能是已在iOS6.x中修复的iOS错误
this is probably an iOS bug that has been fixed in iOS6.x
如果您的情况是使用镜像条件调整图像大小,您可以使用这种方式:
if your case is resizing the image with a mirror criteria you can use this way:
创建一个UIImage类别并添加此实例方法:
create a category of UIImage 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;
}
方法:
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger的)leftCapWidth topCapHeight:(NSInteger的)topCapHeight
iOS的文档中,但不是在框架已被弃用,这意味着您可以在iOS5.x设备中运行应用程序时使用它,没有任何问题,并使用iOS 6或更高版本的设备使用新支持的方法。
has been deprecated in the iOS documentation but not in the framework, this mean that you can use it when you are running your app in a device whit iOS5.x without any problem, and user the new supported method with devices with iOS 6 or higher.
这篇关于使用resizableImageWithCapInsets崩溃:UIEdgeInsetsMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!