我是iOS的新手,现在正在开发一个像室内导航系统这样的应用程序,该视图包含滚动视图,它包含图像视图持有我的地图,当讨厌附近的信标时,我得到它的坐标(x,y)并在图像上成功绘制一个蓝色点,但是如果我放大或缩小绘图功能会在错误的地方绘制。
问:绘制点时如何忽略缩放状态?
我的代码:
self.scrollView.minimumZoomScale = 1.0
self.scrollView.maximumZoomScale = 2.5
绘图代码为:
extension UIImageView {
func addDashedLine(fromPoint start: CGPoint, toPoint end:CGPoint) {
print("Make sure of startr point")
print(start)
let line = CAShapeLayer()
let linePath = UIBezierPath()
linePath.move(to: start)
linePath.addLine(to: end)
line.path = linePath.cgPath
line.strokeColor = UIColor.blue.cgColor
line.lineWidth = 3
line.lineJoin = kCALineJoinRound
line.lineDashPattern = [1, 1]
line.zPosition = 2
self.layer.addSublayer(line)
}
}
并使用它的任何我的代码,例如:
let start = CGPoint(x: oldX, y: oldY)
let end = CGPoint(x: newX, y: newY)
print("old ponit is (start)")
self.mapView.addDashedLine(fromPoint: start, toPoint: end)
移动代码是:
UIView.animate(withDuration: 2.0, delay: 0.0, options: UIViewAnimationOptions.curveLinear, animations: {
self.dotBlue.center = CGPoint(x: x, y: y)
self.defaults.set(CGFloat(x), forKey: "currentLocationX")
self.defaults.set(CGFloat(y), forKey: "currentLocationY")
}, completion: { (finished: Bool) in
print("Animation Ended!")
});
谢谢。
您可以使用 MKMapView
的 isZoomEnabled
属性。
所以像
self.mapView.isZoomEnabled = false
let start = CGPoint(x: oldX, y: oldY)
let end = CGPoint(x: newX, y: newY)
print("old point is (start)")
self.mapView.addDashedLine(fromPoint: start, toPoint: end)
self.mapView.isZoomEnabled = true
只需确保您禁用的任何内容在绘图完成后立即重新启用即可。