There have been similar questions before and I have referred to Capturing touches on a subview outside the frame of its superview using hitTest:withEvent: and Delivering touch events to a view outside the bounds of its parent view. But they do not seem to answer my particular problem.
I have a custom control with the following structure:
+-------------------------------+
| UIButton |
+-------------------------------+
| |
| |
| UITableView |
| |
| |
+------------------------- +
The custom control overrides the UIButton
subclass and adds the UITableView
as its subView. The idea is to have the whole control act like a dropdown. When the UIButton
is pressed, the UITableView
will dropdown and enable selection of a choice.
This all works fine with the hitTest
overridden in UIButton
as described in the Apple's Q&A link above, if the control is an immediate child of the topmost UIView
. However, if the control is in another view hierarchy, the UITableView
is not receiving touch events.
The following is the hitTest code used:
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
// Convert the point to the target view's coordinate system.
// The target view isn't necessarily the immediate subview
let pointForTargetView = self.spinnerTableView.convertPoint(point, fromView:self)
if (CGRectContainsPoint(self.spinnerTableView.bounds, pointForTargetView)) {
// The target view may have its view hierarchy,
// so call its hitTest method to return the right hit-test view
return self.spinnerTableView.hitTest(pointForTargetView, withEvent:event);
}
return super.hitTest(point, withEvent: event)
}
Edit:
I apologise for not having been able to look at the answers and check if they resolve the issue, due to some other tasks that require immediate attention. I shall check them and accept one that helps. Thanks for your patience.
Aucun commentaire:
Enregistrer un commentaire