TapGestureRecognizer超出界限不起作用

时间:2018-03-19 03:58:58

标签: c# android xamarin xamarin.forms xamarin.ios

我正在尝试使用5个标签实现一个小GridView:

  • “设置1”
  • “设置2”
  • “更多设置”
  • “设置4”
  • “设置5”

这些标签中的每一个都附加到 TapGestureRecognizer

您无法在第一时间看到设置4和5,它们位于屏幕下方。

如果按"More settings"标签/按钮,则通过“LayoutTo”向上推整个网格,可以看到最后两个设置。

  • “设置1”
  • “设置2”
  • “设置4”
  • “设置5”

现在我的问题是最后两个标签的最后两个TapGestureRecognizer不起作用。 我在这里发现了一个有类似问题的人: https://forums.xamarin.com/discussion/36094/offscreen-tapgesturerecognizer-not-firing

我尝试了这篇文章中陈述的所有内容,我将主要布局更改为AbsoluteLayout,并使用LayoutTo而不是TranslateTo,但它仍无效。

如果有人知道如何让这些TapGestureRecognizers工作或如何解决我用一点动画“拖出”我的GridView条目的问题,而不必依赖于将内容放在屏幕边界之外我会非常高兴。

这里有一些我的xaml代码:

<AbsoluteLayout x:Name="rellay">
<Grid x:Name="MainGrid" 
        AbsoluteLayout.LayoutBounds="0, 0, 1, .9" AbsoluteLayout.LayoutFlags="SizeProportional">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition x:Name="MapRow" Height="*" />
        <RowDefinition x:Name="DataRow" />
    </Grid.RowDefinitions>
    <maps:Map x:Name="map" Grid.Row="0" />
    <Grid RowSpacing="0" ColumnSpacing="0" x:Name="SecondGrid" Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="62" x:Name="StartRow" />
            <RowDefinition Height="62" x:Name="DestRow" />
            <RowDefinition Height="62" x:Name="OptRow" />
            <RowDefinition Height="62" x:Name="NameRow" />
            <RowDefinition Height="62" x:Name="PhoneRow" />
            <RowDefinition Height="62" x:Name="ZeitRow" />
            <RowDefinition Height="62" x:Name="DetailsRow" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="40" />
            <ColumnDefinition Width="1" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="40" />
        </Grid.ColumnDefinitions>

... (labels and TapGestureRecognizers)

页面-构造:

DataRow.Height = 3 * 62;

“拖带-按钮”:

OptRow.Height = 0;
rellay.LayoutTo(new Rectangle(0, -3 * 62, rellay.Width, rellay.Height), 250, Easing.Linear);

我还尝试直接将类似于条目的东西放入边界之外的AbsoluteLayout(没有网格),然后用LayoutTo将其推高但是它也不起作用,在这种情况下条目“死”。 / p>

1 个答案:

答案 0 :(得分:0)

您的最后两个标签位于MainGrid,但您将其LayoutBounds的高度设置为.9。这可能会让这两个标签在MainGrid之外。即使您在LayoutTo() AbsoluteLayout时可以看到它们,也无法控制底部区域。这就是为什么你把它改成入门,它也不能被触及。

您可以尝试展开rellay的高度:rellay.LayoutTo(new Rectangle(0, -3 * 62, rellay.Width, rellay.Height + 3 * 62), 250, Easing.Linear);以触及这两个标签。但我真的建议你使用ScrollView

创建自定义scrollView:

public class MyScrollView : ScrollView
{
}

然后使用此控件包装AbsoluteLayout

<local:MyScrollView x:Name="MyScroll">
    ...put your other controls here
</local:MyScrollView>

如果要显示标签,请使用以下方法推送:

MyScroll.ScrollToAsync(0, 62 * 3, true);

最后,如果要在触摸和拖动时禁用其滚动,请创建Custom Renderer以实现此目的:

[assembly: ExportRenderer(typeof(MyScrollView), typeof(MyScrollRenderer))]
namespace ExpandLayoutDemo.iOS
{
    public class MyScrollRenderer : ScrollViewRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            ScrollEnabled = false;
        }
    }
}
相关问题