gpt4 book ai didi

ios - 将 'float [2]' 类型的可保留参数传递给期望 'const CGFloat *'(又名 'const double *')类型的 CF 函数的不兼容指针类型

转载 作者:可可西里 更新时间:2023-11-01 06:18:03 30 4
gpt4 key购买 nike

我得到这个错误,我在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;
}

最佳答案

在 64 位架构(如 arm64)上,CGFloat 被定义为 double,因此8 字节 float ,而 float 是 4 字节 float 。因此,您不能传递 float[] 数组到需要 CGFloat[] 数组的函数。

将数组更改为

CGFloat lengths[] = {4,5};

应该可以解决问题。

关于ios - 将 'float [2]' 类型的可保留参数传递给期望 'const CGFloat *'(又名 'const double *')类型的 CF 函数的不兼容指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25783422/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com