简体   繁体   中英

Xamarin Forms - TapGestureRecognizer not working for iOS

I am creating list of image in a loop and attaching a TapGestureRecognizer to each of them to run a method. It is working on Android but not on iOS. Why is that? Is there a problem with it being in a Grid or in a ScrollView?

Here is my code:

foreach (var i in files)
        {
            Image image = new Image { Aspect = Aspect.AspectFit };
            image.Source = ImageSource.FromUri(new System.Uri(i));
            Button button = new Button();
            link = i;

            var tapGestureRecognizer = new TapGestureRecognizer();
            tapGestureRecognizer.Tapped += (s, e) =>
            {
                ViewImage(i);

            };

            image.GestureRecognizers.Add(tapGestureRecognizer);
            gridy.Children.Add(image, 0, num);
            num++;
        }

Here is my 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="YHTS.Gallery"
         Title="Gallery"
         BackgroundColor="Black">

<ScrollView >
    <Grid x:Name="gridy">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
    </Grid>
</ScrollView>

设置InputTransparent="True"的中View

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM