Benjamin Biddle Benjamin Biddle - 2 months ago 19
iOS Question

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>



Answer Source

set InputTransparent="True" of the View