je la structure suivante des vuesblocs UIView HitTest cliquez dans les vues enfant
UIView(1)
|--> UIScrollView
|-----------> UIView(2)
|------> UIButton
hitTest dans UIView (1) a été remplacé par le texte suivant:
- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
{
/* this view should have only view only: the scroll view */
UIView * vv = [[self subviews] objectAtIndex:0];
if ([vv pointInside:point withEvent:event])
{
UIView *rv = [vv hitTest:point withEvent:event];
return rv;
}
if ([self pointInside:point withEvent:event])
{
return vv;
}
return nil;
}
Ceci est nécessaire afin d'attraper UIScrollView glisser en dehors de la vue de défilement elle-même.
Le problème est que lorsque vous cliquez sur l'UIButton, l'événement qui lui est associé ne se déclenche pas. La vue renvoyée par le hitTest est UIView (2).
Comment puis-je faire le UIButton pour répondre à un événement de clic?
Modifier Après suggestion de Mundi, j'échangèrent hitTest avec ce qui suit et il fonctionne. Bien sûr, j'ai oublié d'appeler [super hitTest:].
- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
{
/* this view should have only view only: the scroll view */
UIView * scrv = [self findScrollView];
UIView *superView = [super hitTest:point withEvent:event];
if (superView == self)
{
return scrv;
}
return superView;
}