It is very easy to allow users to interact with views while animating using the options field of block based animation. But in my program I am using a CAKeyframeAnimation and I
You are most likely touching the wrong place. When the layer animates on screen the value never changes so the view is actually positioned where it was from the beginning, not where it appears on screen.
I did a blog post a few month ago on how to hit test animating layers. It describes the exact thing that you are trying to do.
You will need to add the touch handling (or gesture recognizer) to the superview and do the hit-testing of the presentationLayer
yourself to determine if the user tapped where the view appeared on screen.
Apparently, preview solution no longer works in Swift 3.x and Swift 4.x
I solved the issue setting a Timer to update the frame during the animation.
//Timer: To update the UI frame
Timer.scheduledTimer(timeInterval: 0.15, target: self, selector: #selector(updateFrame), userInfo: nil, repeats: true)
//Timer Selector
@objc func updateFrame(){
//getting the layer presentation bounds
let layer = "button, label...".layer.presentation()!
let point = CGPoint(x: layer.frame.origin.x, y: layer.frame.origin.y)
let size = CGSize(width: layer.frame.width, height: layer.frame.height)
// Update the UI element frame location
"ui element".frame = CGRect(origin: point, size: size)
}