在图片视图上设置图钉,然后在拖动和缩放图像上移动该图钉

时间:2019-04-18 11:47:43

标签: ios swift drag-and-drop uiimageview uipinchgesturerecognizer

我试图用imageview将大头针图像放在tap的{​​{1}}上,然后用手指移动大头针图像或用光标拖动,然后在我设置大头针后用捏放大图像视图

首先,我将向您展示TapGesture代码,从中我将代码下面的PIN图像添加到imageview中

TapGesture

使用高位代码,我将pin图片添加到imageview中,然后在我使用下面的代码移动pin图片之后

        let lpgr = UITapGestureRecognizer(target: self, action: #selector(handleLongPress))
        lpgr.delaysTouchesBegan = true
        lpgr.delaysTouchesEnded = true
        lpgr.delegate = self
        viewMainPin.addGestureRecognizer(lpgr)



      @objc func handleLongPress(sender: UITapGestureRecognizer) {

        imageView = UIImageView(frame: CGRect(x: 162, y: 308, width: 50, height: 50))
        imageView.image = UIImage(named: "ic_Pin")
        viewMainPin.addSubview(imageView)
        viewMainPin.isUserInteractionEnabled = false
      }

从所有这些代码中,我可以得到理想的结果,但是现在我想在放下销钉后放大图像

让我告诉我我尝试缩放的代码

var imageView = UIImageView()
var location = CGPoint(x: 0, y: 0)

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        //var touch : UITouch! = touches.anyObject() as UITouch
        location = touch.location(in: self.view)
        imageView.center = location
    }

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        //var touch : UITouch! = touches.anyObject() as UITouch
        location = touch.location(in: self.view)
        imageView.center = location
    }

但这些代码图像已移动,但缩放不起作用

所以请任何人告诉我如何进行缩放和一起移动,请帮助我

0 个答案:

没有答案