I have a UIView
instance that I am animating using CAKeyframeAnimation
. It is a looping animation and will be constantly in motion. However, I need to allow user interaction with the item (responding to taps, to be exact). Because CoreAnimation is only moving the presentation layer and not the model, I cannot use a UIButton
instance, for example, to essentially get the touchUpInside
events.
Consider the following basic example layout:
I am using the blue box for touch events by overriding the touchesEnded:withEvent:
method on a UIView
subclass. I am then bubbling that event through an NSNotification
(I really don't want to introduce a lot of coupling to handle this event) to the containing view controller, which then does a hitTest:
on the red box being animated.
All of this seems rather hacky to just be able to touch an animated UIView
. What are some of the best patterns for handling touches for animated UIView
/CALayer
instances?