Tap Gesture on animating UIView not working

后端 未结 6 1800
南笙
南笙 2020-12-19 18:26

I have a tap gesture on a UILabel who\'s translation is being animated. Whenever you tap on the label during the animation there\'s no response from the tap gesture.

<
6条回答
  •  眼角桃花
    2020-12-19 18:56

    If you want to see the animation, you need to put it in the onTap handler.

    let gesture = UITapGestureRecognizer(target: self, action: "onTap:")
    gesture.numberOfTapsRequired = 1
    label.addGestureRecognizer(gesture)
    label.userInteractionEnabled = true
    
    label.transform = CGAffineTransformMakeTranslation(0, 0)
    
    UIView.animateWithDuration(12, delay: 3, options: [.AllowUserInteraction], animations: { () -> Void in
          label.transform = CGAffineTransformMakeTranslation(0, 900)
          }, completion: nil)
    
    
    func onTap(sender : AnyObject)
    {
    
        print("Tapped")
    }
    

提交回复
热议问题