相关疑难解决方法(0)

CGContextStrokePath 在 iOS > 5 中触发 EXC_BAD_ACCESS

我有一个自定义 UIButton 类,它为 UIButton 添加渐变和光泽效果,代码在 iOS 4 和 iOS5 模拟器上完美运行,但是当我在 iOS 5 设备上运行它时,它给了我异常 EXC_BAD_ACCESS ,异常由线 :

CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)

非常感谢任何帮助,这是我的代码

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGFloat actualBrightness = _brightness;
    if (self.selected) {
        actualBrightness -= 0.10;
    }   

    CGColorRef blackColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0].CGColor;
    CGColorRef highlightStart = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.7].CGColor;
    CGColorRef highlightStop = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0].CGColor;

    CGColorRef outerTop = [UIColor colorWithHue:_hue saturation:_saturation brightness:1.0*actualBrightness alpha:1.0].CGColor;
    CGColorRef outerBottom = [UIColor colorWithHue:_hue saturation:_saturation brightness:0.80*actualBrightness alpha:1.0].CGColor;

    CGFloat outerMargin = 7.5f; …
Run Code Online (Sandbox Code Playgroud)

exc-bad-access objective-c quartz-2d ios4 ios5

5
推荐指数
1
解决办法
1171
查看次数

EXC_BAD_ACCES绘制阴影

我想为我的UIView添加一个阴影,但在我的drawRect方法中,我得到一个EXC_BAD_ACCESS.(我正在使用ARC)

-(void) drawRect:(CGRect)rect {

    CGColorRef lightColor =  [UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8].CGColor;

    CGColorRef shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4].CGColor;   

    CGContextRef context = UIGraphicsGetCurrentContext();
    // Draw shadow
    CGContextSaveGState(context);
    CGContextSetShadowWithColor(context, CGSizeMake(-5, 0), 10, shadowColor);
    CGContextSetFillColorWithColor(context, lightColor);
    CGContextFillRect(context, _coloredBoxRect);
    CGContextRestoreGState(context);
}
Run Code Online (Sandbox Code Playgroud)

错误消息: 线程1:编程接收信号:"EXC_BAD_ACCESS".

线: CGContextSetFillColorWithColor(context, lightColor);

当我将此行更改为:

[[UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8] setFill];
Run Code Online (Sandbox Code Playgroud)

我得到了相同的错误,但在这一行:

CGContextSetShadowWithColor(context, CGSizeMake(-5, 0), 10, shadowColor);
Run Code Online (Sandbox Code Playgroud)

更新 我最终通过更改解决了问题:

CGColorRef shadowColor = [UIColor colorWithRed:0.2绿色:0.2蓝色:0.2 alpha:0.4] .CGColor;

float components [4] = {0,0,0,1.0/3.0}; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGColorRef shadowColor = CGColorCreate(colorSpace,components); …

core-graphics uiview cgcontext ios automatic-ref-counting

3
推荐指数
1
解决办法
1566
查看次数

关于自动引用计数,我需要了解什么?

我有一个应用程序我正在更新到最新版本的Xcode,并且遇到了与自动引用计数(ARC)相关的多个错误.

这些错误让我打电话给例如,autorelease并调整我编写的处理内存管理的其他代码.

锵文件上写着:

[ARC]不提供循环收集器; 用户必须明确管理生命周期.

......这让我很紧张 过去,我一直被Objective-C内存管理问题所困扰retain,release并且autorelease在我的代码中依赖于验证每一个.

现在,ARC正在呼唤我改变我的内存管理语义.为了建立对ARC内存管理的信心,我需要知道什么?

xcode memory-management objective-c clang automatic-ref-counting

2
推荐指数
1
解决办法
162
查看次数