1

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

虚线在绘制时工作正常,但是当我导航回上一页并再次进入绘图视图时,它当时崩溃了。我调试了代码,发现它在解码“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"];
 }

在 Drawrect 中:

-(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 天了。请帮我

4

1 回答 1

1

我知道这是一个老问题,但以防万一你还在研究它,

您是否尝试过更改:

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

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

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

于 2015-01-20T05:08:52.257 回答