我有一张图片需要在另一张图片的顶部拖动。当您触摸它时,touchesBegan仅在您触摸图像顶部或其正上方的图像时才会注册。触摸图像的中心或顶部以外的任何其他部分根本不起作用。我是否正确设置了它?
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = selectedPhoto
watermarkImageView.image = selectedWatermark
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInView(self.view)
if watermarkImageView.frame.contains(location) {
watermarkImageView.center = location
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInView(self.view)
if watermarkImageView.frame.contains(location) {
watermarkImageView.center = location
}
}
}
答案 0 :(得分:0)
两个图像视图都嵌套在另一个视图中。我不得不更改location
来反映这一点。
let location = touch.locationInView(imageContainerView)