我想问您有关移动UIImageView的问题。
让我们假设UIImageView位于位置X1。如果我想使用拖动事件将imv移至位置X2,该如何实现?
请给我建议。谢谢阅读。
我指的是How to drag UIImageView using touches method
import UIKit
class ViewController: UIViewController {
@IBOutlet var imgView: UIImageView!
var imgMarker:UIImage?
var location = CGPoint()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
imgMarker = UIImage(named: "marker.png")
imgView.image = imgMarker
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
if let touch = touches.first {
location = touch.location(in: self.view)
imgView.center = location
}
}
}