4

我得到这个错误,我在arm64下编译出现这个错误:

CGContextSetLineDash(line, 0, lengths, 1);  //画虚线

我该如何解决这个问题?

- (id)initDashLineWithFrame:(CGRect)frame{
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:frame];

    UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线
    [imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状


    float lengths[] = {4,5};
    CGContextRef line = UIGraphicsGetCurrentContext();
    UIColor *coloreline = [UIColor colorWithRed:156/255.0 green:156/255.0 blue:156/255.0 alpha:1];//r(156, 156, 156, 1);
    CGContextSetStrokeColorWithColor(line, coloreline.CGColor);

    CGContextSetLineDash(line, 0, lengths, 1);  //画虚线
    CGContextMoveToPoint(line, 0.0, 5.0);    //开始画线
    CGContextAddLineToPoint(line, 310.0, 5.0);
    CGContextStrokePath(line);

    imageView1.image = UIGraphicsGetImageFromCurrentImageContext();
    return imageView1;
}
4

1 回答 1

20

在 64 位架构(如 arm64)CGFloat上,定义为double8 字节浮点数,而float4 字节浮点数。因此,您不能将数组传递给需要float[]数组的函数CGFloat[]

将您的阵列更改为

CGFloat lengths[] = {4,5};

应该解决问题。

于 2014-09-11T09:16:29.140 回答