Xamarin Forms TapGestureRecognizer 不工作 iOS

Xamarin Forms TapGestureRecognizer not working iOS

我一直面临一个问题,很多问题过去都遇到过,但 none 的解决方案似乎有效。

我有一个网格,其中有一个带有 TapGesture 的 StackLayout。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:local="clr-namespace:WodTracker.App.Components"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="WodTracker.App.Pages.Account.PinCodePage"
             BackgroundColor="White">
    <ContentPage.Content>
        <StackLayout VerticalOptions="FillAndExpand" BackgroundColor="White">
            <StackLayout.GestureRecognizers>
                <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="NumberCommand" CommandParameter="1"/>
            </StackLayout.GestureRecognizers>
            <Label HorizontalOptions="Center" VerticalOptions="EndAndExpand"  Text="1"  FontSize="Title" FontAttributes="Bold" TextColor="Black"></Label>
            <Label HorizontalOptions="Center" VerticalOptions="EndAndExpand" Text=" " FontSize="Small" TextColor="Black"></Label>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

应该命中的代码如下。没有在构造函数中初始化只是方法。

private async void NumberCommand(object sender, EventArgs e) 
{
     var button = sender;
}

在 Android 上执行点击命令“NumberCommand”。但是在 iOS 上它不会触发。 关于这个 我发现有人提到

InputTransparent="True"

我已经尝试将它添加到父网格和 StackLayout,但没有成功。

希望有人能提供帮助。

我正在使用 Visual Studio 2022 和 Xamarin Forms 5.0.0.2244

已解决

这是 'InputTransparent="True"' 的一个问题,在根据 ToolmakerSteve 的评论逐步重建页面后,我能够修复它。感谢大家的帮助。

这是 'InputTransparent="True"' 的一个问题,在根据 ToolmakerSteve 的评论逐步重建页面后,我能够修复它。感谢大家的帮助。

代码

<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="White">
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="NumberCommand" CommandParameter="1"/>
                </StackLayout.GestureRecognizers>
                <Label HorizontalOptions="Center" VerticalOptions="EndAndExpand"  Text="1"  FontSize="Title" FontAttributes="Bold" TextColor="Black"></Label>
                <Label HorizontalOptions="Center" VerticalOptions="EndAndExpand" Text=" " FontSize="Small" TextColor="Black"></Label>
</StackLayout>

代码隐藏

private async void NumberCommand(object sender, EventArgs e)
{
    var button1 = (TapGestureRecognizer)sender;
    string commandParameter = button1.CommandParameter.ToString();
}