我有一个编译没有问题的代码.它在iPhone模拟器上运行良好,但在我的设备上,我得到了一个EXC_BAD_ACCESS.
这发生在辅助函数中以绘制渐变.我按照本教程进行操作.我的代码如下:
- (void) drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef whiteColor = [UIColor whiteColor].CGColor;
CGColorRef lightGrayColor = [UIColor colorWithRed:230.0/255.0
green:230.0/255.0
blue:230.0/255.0
alpha:1.0].CGColor;
CGColorRef separatorColor = [UIColor colorWithRed:208.0/255.0
green:208.0/255.0
blue:208.0/255.0
alpha:1.0].CGColor;
CGRect paperRect = self.bounds;
CGRect nameRect = self.nameLabel.frame;
CGPoint sepStartPoint = CGPointMake(nameRect.origin.x,
nameRect.origin.x + nameRect.size.height + 2);
CGPoint sepEndPoint = CGPointMake(nameRect.origin.x + nameRect.size.width,
nameRect.origin.x + nameRect.size.height + 2);
drawLinearGradient(context, paperRect, lightGrayColor, whiteColor);
draw1PxStroke(context, sepStartPoint, sepEndPoint, separatorColor);
}
// Callee, where the problem is
void drawLinearGradient(CGContextRef context,
CGRect …
Run Code Online (Sandbox Code Playgroud)