gpt4 book ai didi

swift - '(整数,整数 )' is not identical to ' CGPoint'

转载 作者:搜寻专家 更新时间:2023-11-01 05:59:22 25 4
gpt4 key购买 nike

我收到错误:'(Int, Int)' 与 'CGPoint' 不相同

如何将 (Int, Int) 转换为 CGPoint

let zigzag = [(100,100),
(100,150),(150,150),
(150,200)]

override func drawRect(rect: CGRect)
{
// Get the drawing context.
let context = UIGraphicsGetCurrentContext()

// Create the shape (a vertical line) in the context.
CGContextBeginPath(context)

//Error is here
CGContextAddLines(context, zigzag, zigzag.count)

// Configure the drawing environment.
CGContextSetStrokeColorWithColor(context,UIColor.redColor().CGColor)

// Request the system to draw.
CGContextStrokePath(context)
}

最佳答案

CGContextAddLines() 需要一个 CGPoint 数组。如果你已经有一个(Int, Int) 元组的数组然后你可以用

转换它
let points = zigzag.map { CGPoint(x: $0.0, y: $0.1) }

关于swift - '(整数,整数 )' is not identical to ' CGPoint',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26798105/

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