Tap Gesture on animating UIView not working

后端 未结 6 1782
南笙
南笙 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:57

    Below is a more generic answer based on the answer from @agibson007 in Swift 3.

    This didn't solve my issue immediately, because I had additional subviews covering my view. If you have trouble, try changing the extension type and writing print statements for touchLocation to find out when the function is firing. The description in the accepted answer explains the issue well.

    extension UIViewController {
    
        open override func touchesBegan(_ touches: Set, with event: UIEvent?) {
    
            guard let touch = touches.first else { return }
            let touchLocation = touch.location(in: self.view)
    
            for subview in self.view.subviews {
    
                if subview.tag == VIEW_TAG_HERE && subview.layer.presentation()?.hitTest(touchLocation) != nil {
    
                    print("[UIViewController] View Touched!")
                    // Handle Action Here
    
                }
    
            }
    
        }
    
    }
    

提交回复
热议问题