CGColorRef导致崩溃 [英] CGColorRef causing crash

查看:100
本文介绍了CGColorRef导致崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码崩溃了,并且在传递2个CGColorRefs时我一直跟踪到一线崩溃。以下是对象:

I've had a crash in my code, and I've tracked it all the way back to a line crashing when being passed 2 CGColorRefs. Here are the objects:

CGColorRef startColor = [[UIColor colorWithWhite:0.92 alpha:1.0]CGColor];
CGColorRef endColor = [[UIColor colorWithWhite:0.94 alpha:1.0]CGColor];

NSLog(@"start: %@ end: %@", startColor, endColor);

NSLog返回崩溃。他们有什么问题?

The NSLog returns a crash. What's wrong with them?

编辑 - 它崩溃的地方:

EDIT - where it's crashing:

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat locations[] = { 0.0, 1.0 };
NSArray *colors = [NSArray arrayWithObjects:(__bridge_transfer id)startColor, (__bridge_transfer id)endColor, nil];


推荐答案

ARC。弧。弧。 UIColor-> CGCOlor是ARC最大的陷阱之一......

ARC. ARC. ARC. UIColor->CGCOlor is one of ARC's big gotchas...

在这里深入了解:

< a href =http://weblog.bignerdranch.com/?p=296 =noreferrer> http://weblog.bignerdranch.com/?p=296

我在这里写了一些关于ARC的一般最佳实践(包括你的问题):

And I wrote up some general best practices for ARC (including your problem) here:

http://amattn.com/2011/12/07/arc_best_practices.html

这篇关于CGColorRef导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆