Capturing touches on a preview outside of his supervisor (at several levels)

I have a similar problem described in this thread: Capturing strokes on a preview outside of its supervisor using hitTest: withEvent:

Situation

We are developing an application in Xamarin iOS. We have a custom view to create our own autocomplete input field containing the UiTextField and UiTableView below to show the results.

To achieve better modularity, we have another custom view called LabeledContainer. Inside this, I can set a shortcut and add content to the bottom view, which is autocomplete in this case.

AutoComplete               LabeledContainer
+---------------+          +---------------+
| UiView        |          | UiView        |
|+-------------+|          |+-------------+|
|| UiTextField ||          || UiLabel     ||
|+-------------+|          |+-------------+|
|+-------------+|          |+-------------+|
|| UiTableView ||          || UiView      ||
|+-------------+|          |+-------------+|
+---------------+          +---------------+

The following gets rendered:
MAINVIEW
+------------------------------+
|                              |
|                              |
|                              |
|                              |
|+----------------------------+|
|| LabeledContainer           ||
||+--------------------------+||
||| Label                    |||
||+--------------------------+||
||+--------------------------+||
||| Content                  |||
|||+------------------------+|||
|||| AutoComplete           ||||
|||+------------------------+|||
||+--------------------------+||
|+----------------------------+|
|                              |
|                              |
|                              |
|                              |
+------------------------------+

Problem

"hitarea", autoComplete (tableView) . , . , hitArea.

public override bool PointInside(CGPoint point, UIEvent uievent)
{
    var bounds = Bounds;
    bounds.Height += DROPDOWN.Bounds.Height;   
    return bounds.Contains(point);
}

, autoComplete subChild mainView, PointInside . autoComplete labeledContainer, + , PointsInside . , , ? PointsInside , ? labeledContainer autoComplete , .

PointsInside labeledContainer, , labeledContainer PointsInside .

+4
2

UIViews . . .

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    CGPoint pointForTargetView = [self.autoCompleteView convertPoint:point fromView:self];

    if (CGRectContainsPoint(self.autoCompleteView.bounds, pointForTargetView)) {
        return [self.autoCompleteView hitTest:pointForTargetView withEvent:event];
    }
    return [super hitTest:point withEvent:event];
}

Apple:

, , , . , "" , .

+4

, . .

, hitTest . .

// Xamarin version - labeledContainer
public override UIView HitTest(CGPoint p, UIEvent e)
{
    var translatedP = AutoComplete.ConvertPointFromView(p, this);
    return AutoComplete.HitTest(translatedP, e) ?? base.HitTest(p, uievent);
}

, HitTest :

// Xamarin version - autoComplete
public override UIView HitTest(CGPoint p, UIEvent e)
{
    var translatedP = DropDown.ConvertPointFromView(p, this);
    return DropDown.HitTest(translatedP, e) ?? base.HitTest(p, uievent);
}

, . , HitTest .

0

Source: https://habr.com/ru/post/1672828/


All Articles