[英]iOS warning message : Incompatible pointer types passing 'CGFloat *' (aka 'double *') to parameter of type 'float *'
[英]Incompatible pointer types passing retainable parameter of type 'float [2]'to a CF function expecting 'const CGFloat *' (aka 'const double *') type
我收到這個錯誤,我在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
是4字節浮點數。 因此,您無法將float[]
數組傳遞給期望CGFloat[]
數組的函數。
將陣列更改為
CGFloat lengths[] = {4,5};
應該解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.