に次のメソッドがありますUIImageManipulation.m
。
+(UIImage *)scaleImage:(UIImage *)source toSize:(CGSize)size
{
UIImage *scaledImage = nil;
if (source != nil)
{
UIGraphicsBeginImageContext(size);
[source drawInRect:CGRectMake(0, 0, size.width, size.height)];
scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return scaledImage;
}
私は別のビューでそれを呼び出しています:
imageFromFile = [UIImageManipulator scaleImage:imageFromFile toSize:imageView.frame.size];
(imageView は以前に割り当てられた UIImageView です)
これは私のコードでうまく機能しています。画像のサイズを完全に変更し、エラーをスローしません。また、ビルド - >分析の下に何もポップアップしません。NSZombieEnabled
しかし、別の問題をデバッグするためにオンにするEXC_BAD_ACCESS
と、コードが壊れます。毎回。私はNSZombieEnabled
オフにすることができます、コードはうまく動作します。私はそれをオンにし、ブーム。壊れた。呼び出しをコメントアウトすると、再び機能します。毎回、コンソールにエラーが表示されます: -[UIImage release]: message sent to deallocated instance 0x3b1d600
. `NSZombieEnabled がオフになっている場合、このエラーは表示されません。
何か案は?
- 編集 -
わかりました、これは私を殺しています。私はできる限りどこでもブレークポイントをスタックしましたが、まだこのことを把握できません。scaleImage
メソッドを呼び出すときの完全なコードは次のとおりです。
-(void)setupImageButton
{
UIImage *imageFromFile;
if (object.imageAttribute == nil) {
imageFromFile = [UIImage imageNamed:@"no-image.png"];
} else {
imageFromFile = object.imageAttribute;
}
UIImage *scaledImage = [UIImageManipulator scaleImage:imageFromFile toSize:imageButton.frame.size];
UIImage *roundedImage = [UIImageManipulator makeRoundCornerImage:scaledImage :10 :10 withBorder:YES];
[imageButton setBackgroundImage:roundedImage forState:UIControlStateNormal];
}
他のUIImageManipulator
方法 ( makeRoundCornerImage
) がエラーを引き起こしているはずはありませんが、何かを見落としている場合に備えて、ファイル全体を github hereに投げました。
しかし、それはこの方法に関するものです。である必要があります。コメントアウトすると、うまくいきます。入れっぱなしだとエラー。NSZombieEnabled
しかし、これまでオフにしてエラーをスローすることはありません。