UIPanGestureRecognizer在swift的多视图上

时间:2015-07-23 08:41:59

标签: ios swift uipangesturerecognizer

   let pan1 = UIPanGestureRecognizer(target: self, action: "pan:")
    self.dateView1.addGestureRecognizer(pan)
    self.dateView2.addGestureRecognizer(pan)
    self.dateView3.addGestureRecognizer(pan)
    self.dateView4.addGestureRecognizer(pan)

func pan(sender: UIPanGestureRecognizer) {

    let moveView = sender.view!
    let translation = sender.translationInView(self.View)
    moveView.center.x += translation.x
    moveView.center.y += translation.y
    sender.setTranslation(CGPointZero, inView: self.View)

如何在多个视图上使用UIPanGestureRecognizer ... 现在只移动一个视图,点击一个事物,只能移动一个

1 个答案:

答案 0 :(得分:3)

简单回答,你不能。无法将GestureRecognizer分配给多个变量。

但是,您可以创建多个指向相同操作的手势识别器;)

希望这会有所帮助。