在iOS7中使用Bezierpath绘制虚线时出现EXC_ARM_DA_ALIGN异常

时间:2014-08-04 13:57:08

标签: ipad ios7 uibezierpath nscoder

我正在使用Bezier路径对象绘制直线和虚线。 我将这些路径保存在一个文件中,并使用NScoder来保存这些路径 它在iOS 6设备和iOS 7模拟器中工作正常但在iOS 7设备中抛出EXC_ARM_DA_ALIGN错误而不是普通线。

虚线在绘制时工作正常,但当我导航回上一页并再次进入绘图视图时,它就崩溃了。 我调试了代码,发现在解码方法中解码虚线时崩溃了#34; Line_Point.m"文件

//坚持路径

import "Line_Point.h"

@implementation Line_Point
@synthesize point;
@synthesize line_color;
@synthesize line_pattern;
@synthesize path;

-(void)encodeWithCoder:(NSCoder *)encoder
{
    //Encode the properties of the object
    [encoder encodeObject:self.line_pattern forKey:@"line_pattern"];
    [encoder encodeObject:self.line_color forKey:@"line_color"];
    [encoder encodeObject:self.point forKey:@"point"];
    [encoder encodeObject:self.path forKey:@"path"];
}

-(id)initWithCoder:(NSCoder *)decoder
{
    self = [super init];
    if ( self != nil )
    {
        //decode the properties
        self.line_pattern = [decoder decodeObjectForKey:@"line_pattern"];
        self.line_color = [decoder decodeObjectForKey:@"line_color"];
        self.point = [decoder decodeObjectForKey:@"point"];
        self.path = [decoder decodeObjectForKey:@"path"];// this is where i got the   EXC_ARM_DA_ALIGN error
    }
    return self;
}

//画线:

在CanvasViewDirectionalLines.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
        myPath = [UIBezierPath bezierPath] ;
        UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
        [myPath moveToPoint:[mytouch locationInView:self]];

        Line_Point * to_be_added = [[Line_Point alloc] init];
        to_be_added.line_color = [UIColor colorWithCGColor: current_color.CGColor];
        to_be_added.line_pattern = [NSString stringWithString: current_line_pattern];
        if ([to_be_added.line_pattern isEqualToString:@"normal"])
        {
            [myPath setLineWidth:1.0];
            [myPath setLineDash:0 count:0 phase:0];
        }
        else if([to_be_added.line_pattern isEqualToString:@"thick"])
        {
            [myPath setLineWidth:3.0];
            [myPath setLineDash:0 count:0 phase:0];
        }

        else if([to_be_added.line_pattern isEqualToString:@"dotted"])
        {
            CGFloat newLocations[kMyClassLocationCount] = {6.0, 2.0};
            myInstance.patterns = newLocations;
            [myInstance setPatterns:newLocations];
            [myPath setLineWidth:2.0];
            //CGFloat Pattern1[] = {6.0, 2.0};
            //CGFloat *Pattern1 = myInstance.patterns;
            [myPath setLineDash:myInstance.patterns count:2 phase:0];
        }
        else if([to_be_added.line_pattern isEqualToString:@"super_dotted"])
        {

            [myPath setLineWidth:2.0];
            float Pattern[4] = {1, 2, 1, 2};
            [myPath setLineDash:Pattern count:4 phase:0];
        }
        to_be_added.path = myPath;
        [pathArray addObject:to_be_added];
        [track_of_activites addObject:@"freeform_tool"];
 }

直截了当:

-(void)drawRect:(CGRect)rect
{
    for(int i=0; i<pathArray.count; i++){
        Line_Point * first = [[pathArray objectAtIndex:i] retain];
        [first.line_color  setStroke];
        [first.path stroke];
    }
}

我一直试图解决这个问题3天。 请帮帮我

1 个答案:

答案 0 :(得分:1)

我知道这是一个老问题,但万一你还在努力,

您是否尝试过更改:

float Pattern[4] = {1, 2, 1, 2}; [myPath setLineDash:Pattern count:4 phase:0];

在super_dotted绘图方法中使用CGFloat而不是float(因为这应该是setLineDash方法所期望的)。像这样:

[myPath setLineWidth:2.0]; CGFloat Pattern[4] = {1, 2, 1, 2}; [myPath setLineDash:Pattern count:4 phase:0];