超出范围的 TapGestureRecognizer 不起作用 [英] TapGestureRecognizer outside of bounds doesn't work

查看:23
本文介绍了超出范围的 TapGestureRecognizer 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个带有 5 个标签的小 GridView:

I am trying to implement a little GridView with 5 labels:

  • 设置 1"
  • 设置 2"
  • 更多设置"
  • 设置 4"
  • 设置 5"

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

Each of these labels are attached to a TapGestureRecognizer.

您一开始看不到设置 4 和 5,它们在屏幕下方.

如果您按下 更多设置" 标签/按钮,通过使用LayoutTo"向上推动整个网格,最后两个设置变得可见.

If you press the "More settings" label/button the last two settings become visible by pushing the entire Grid upwards with "LayoutTo".

  • 设置 1"
  • 设置 2"
  • 设置 4"
  • 设置 5"

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

Now my problem is that the last two TapGestureRecognizers of the last two labels don't work. I found someone with a similar problem here: https://forums.xamarin.com/discussion/36094/offscreen-tapgesturerecognizer-not-firing.

我尝试了这篇文章中提到的所有内容,我将主布局更改为 AbsoluteLayout 并使用 LayoutTo 而不是 TranslateTo 但它仍然没有不行.

I tried everything stated in this post, I changed my main layout to an AbsoluteLayout and used LayoutTo instead of TranslateTo but it still doesn't work.

如果有人知道如何让这些 TapGestureRecognizers 工作,或者如何解决我用一点动画拖出"我的 GridView 条目的问题,但不必依赖于将内容从屏幕边界我会很高兴.

If anyone has an idea how to get these TapGestureRecognizers to work or how to solve my problem of "dragging out" my GridView entries with a little animation but without having to rely on putting content out of screen bounds I would be very happy.

这里是我的一些 xaml 代码:

Here some of my xaml code:

<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 将其向上推,但它也不起作用,在这种情况下,条目已死亡".

I also tried to directly put stuff like an entry into the AbsoluteLayout (without Grids) outside of bounds and then push it up with LayoutTo but then it doesn't work either, the entry is "dead" in that case.

推荐答案

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

Your last two labels are placed in MainGrid, but you set its LayoutBounds's height to .9. This may let these two labels outside of the MainGrid. Even though they can be seen when you LayoutTo() the AbsoluteLayout, the bottom area can't be controlled. This is why you change it to entry, it can't be touched neither.

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

You can try to expand the rellay's height: rellay.LayoutTo(new Rectangle(0, -3 * 62, rellay.Width, rellay.Height + 3 * 62), 250, Easing.Linear); to let these two labels touched. But I really recommend you to use ScrollView.

创建自定义滚动视图:

public class MyScrollView : ScrollView
{
}

然后使用这个控件包裹AbsoluteLayout

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

当你想显示标签时,使用:

When you want to show the labels, push it using:

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

最后,如果您想在触摸和拖动时禁用其滚动,请创建一个 Custom Renderer 来实现这个:

At last, if you want to disable its scrolling when touching and dragging it, create a Custom Renderer to achieve this:

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

            ScrollEnabled = false;
        }
    }
}

这篇关于超出范围的 TapGestureRecognizer 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆