func addLine(fromPoint start: CGPoint, toPoint end:CGPoint) {
let line = CAShapeLayer()
let linePath = UIBezierPath()
linePath.move(to: start)
linePath.addLine(to: end)
line.path = linePath.cgPath
line.strokeColor = UIColor.red.cgColor
line.lineWidth = 1
line.lineJoin = CAShapeLayerLineJoin.round
self.view.layer.addSublayer(line)
}
用法:-addLine(fromPoint: yourFirstView.center, toPoint: yourSecondView.center)
请确保在调用此函数时可以访问您的视图