I have a UIButton and a UIView. The View sits above the button, and is larger than the button in size. The view itself is what I want to have accept the touch events, and I'd like to forward them to the button, so that all the normal button visual changes on touch happen.
I can't seem to make this work-- my UIView implements touchesBegan/Moved/Ended/Cancelled, and turns around and calls the same methods on the button with the same arguments. But the button doesn't respond.
I have ensured that the touch methods are in fact being called on the UIView.
Is there something obvious I'm missing here, or a better way of getting the control messages across? Or is there a good reason why this shouldn't work?
Thanks!
[Note: I'm not looking for workarounds for the view+button design. Let's assume that that's a requirement. I'm interested in the notion of controls that are touch proxies for other controls. Thanks.]
Create a ContainerView
that contains a button and override hitTest:withEvent:
so that it returns the UIButton instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With