我已经创建了测量演示,允许放置多个点并显示它们之间的距离。哪个很好用
我想显示预览,使用
uibezierPath在现实世界中绘制到uiview的内容。就像
http://armeasure.com/
我已经尝试了很多事情来实现这一点,但我找不到任何正确的方法来实现。
if self.linklist.count==1{
bezierPath.removeAllPoints()。
移动(到:cgpoint(x:10,y:10))。
}其他{
guard self.linklist.count>1,让object2=self.linklist.lastnode,让object1=self.linklist.lastnode?.上一个else返回
让value=self.getMeasurementXandyBetween(vector1:object1.node.mainnode.position,and:object2.node.mainnode.position)
打印(值)
设x=double((object1.node.mainnode.position.x+value)*377.9527559055)
设y=double((object1.node.mainnode.position.y+value)*377.9527559055)
设点坐标=cg点(x:x,y:y)
打印(“X:Y”,X,Y)
bezierPath.addLine(到:点坐标)
}
shapelayer.removeFromSuperlayer()。
shapelayer.path=bezierpath.cgpath
shapelayer.linewidth=0.5
shapelayer.fillColor=uicolor.clear.cgcolor
shapelayer.strokeColor=uicolor.red.cgcolor
shapelayer.position=cgpoint(x:0,y:0)
self.viewToDraw.layer.addSublayer(shapelayer)
func getmeasurementsxandybetween(vector1:scnvector3和vector2:scnvector3)->float{
返回sqrtf((vector1.x-vector2.x)*(vector1.x-vector2.x)+(vector1.y-vector2.y)*(vector1.y-vector2.y))
}
我使用的逻辑(不工作)是上一个节点的位置+我从getMeasurementXandyBetween得到的距离。multiple by 377.
请提出提示或任何其他解决方案
.UIBezierPath. 就像http://armeasure.com/
为了达到这个目标,我做了很多努力,但是我找不到任何正确的方法。
if self.linkList.count == 1 {
bezierPath.removeAllPoints()
bezierPath.move(to: CGPoint(x: 10,y: 10))
} else {
guard self.linkList.count > 1 ,let object2 = self.linkList.lastNode, let object1 = self.linkList.lastNode?.previous else {return}
let value = self.getMeasurementXandYBetween(vector1: object1.node.mainNode.position, and: object2.node.mainNode.position)
print(value)
let x = Double((object1.node.mainNode.position.x + value ) * 377.9527559055 )
let y = Double((object1.node.mainNode.position.y + value) * 377.9527559055)
let pointCoordinates = CGPoint(x: x , y: y)
print("x : Y ",x,y)
bezierPath.addLine(to: pointCoordinates)
}
shapeLayer.removeFromSuperlayer()
shapeLayer.path = bezierPath.cgPath
shapeLayer.lineWidth = 0.5
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.red.cgColor
shapeLayer.position = CGPoint(x: 0, y: 0)
self.viewToDraw.layer.addSublayer(shapeLayer)
func getMeasurementXandYBetween(vector1:SCNVector3, and vector2:SCNVector3) -> Float {
return sqrtf((vector1.x - vector2.x) * (vector1.x - vector2.x) + (vector1.y - vector2.y) * (vector1.y - vector2.y))
}
我使用的逻辑(不起作用)是上一个节点的位置+我到的距离getMeasurementXandYBetween乘以377。
请提出提示或任何其他解决方案
