ios - 无法使用类型为 'float2' 的参数列表调用类型为 'CGPoint' 的初始值设定项

标签 ios swift

嘿,我收到这个错误,这是我下面的代码,我有 import simd 但它不起作用。

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    if let touch = panningTouch {
        let displacement = float2(touch.location(in: view)) - float2(touch.previousLocation(in: view))
        panCamera(displacement)   
    }
}

最佳答案

如错误消息所述,simd.float2 没有采用 CGPoint 的初始化器。但是,您可以添加自己的:

extension float2 {
    init(_ point: CGPoint) {
        self.init(Float(point.x), Float(point.y))
    }
}

关于ios - 无法使用类型为 'float2' 的参数列表调用类型为 'CGPoint' 的初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42102508/

相关文章:

ios - 为什么 applicationWillResignActive 方法不起作用?

ios - Swift:根据父 View 大小动态调整/缩放 UIBezierPath

ios - Xcode 6 创建 Storyboard警告

ios - 尝试将非 ARC 'CallHandler'(调用拦截器)转换为 ARK 遇到问题

ios - 为什么使用自动布局时 View 的框架宽度始终为 600 x 600

Swift:如何将当前 URL 从 UIWebView 放入 UITextField 中?

ios - 具有动态内容的分页滚动

ios - SKPhysicsBody 质量变化中心

swift - 为什么任何Error都可以无条件的转化为NSError?

swift - 为什么在快速传递来自不同 ViewController 的数组元素时数组(collCells)显示为空?