gpt4 book ai didi

xamarin - NumberOfTapsRequired 不适用于 > 2

转载 作者:行者123 更新时间:2023-12-02 13:02:22 25 4
gpt4 key购买 nike

我有 Xamarin Forms 项目,在我的页面上有以下代码:

<Image Source="genea_login_logo.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LogoCommand}" NumberOfTapsRequired="2" />
</Image.GestureRecognizers>
</Image>

它按预期工作。但是,当我将 NumberOfTapsRequired 从 2 更改为 5 时,它不再起作用。这种行为是预期的吗?是否可以实现5键命令?

编辑:这仅适用于 Android。

最佳答案

实际上,具有超过 2 个 NumberOfTapsRequired 的 TapGestureRecognizer 在 Android 中不起作用。您可以实现某种逻辑来实现这种效果。

在 XAML 中

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Demo.Views.MainPage"
Title="MainPage">
<Grid HorizontalOptions="Center" VerticalOptions="Center">

<Image Source="icon.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_OnTapped"/>
</Image.GestureRecognizers>
</Image>

</Grid>
</ContentPage>

代码隐藏...

    private DateTime? LastTap = null;
private byte NumberOfTaps = 0;

private const int NumberOfTapsRequired = 3;
private const int ToleranceInMs = 1000;

private async void TapGestureRecognizer_OnTapped(object sender, EventArgs e)
{
if (LastTap == null || (DateTime.Now - LastTap.Value).TotalMilliseconds < ToleranceInMs)
{
if (NumberOfTaps == (NumberOfTapsRequired - 1))
{

await App.Current.MainPage.DisplayAlert("Hi", "Hi from Gesture", "Ok");

NumberOfTaps = 0;
LastTap = null;
return;
}
else
{
NumberOfTaps++;
LastTap = DateTime.Now;
}
}
else
{
NumberOfTaps=1;
LastTap = DateTime.Now;
}
}

关于xamarin - NumberOfTapsRequired 不适用于 > 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44003547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com