如何忽略缩放图像视图Swift 3

时间:2017-01-10 12:22:13

标签: ios uiscrollview uiimageview swift3 drawimage

我是iOS新手,现在正在开发一个类似室内导航系统的应用程序,该视图包含滚动视图,它包含拿着我的地图的imageView,当我靠近我的坐标(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!")
        });

由于

1 个答案:

答案 0 :(得分:0)

您可以使用isZoomEnabled的{​​{1}}属性。

类似

MKMapView

只需确保在绘图完成后立即重新启用您禁用的内容。