Xamarin Forms - TapGestureRecognizer不适用于iOS

时间:2017-07-17 01:01:43

标签: ios xamarin xamarin.ios xamarin.forms

我在循环中创建图像列表并附加  一个TapGestureRecognizer为他们每个人运行一个方法。它适用于Android,但不适用于iOS。这是为什么?它是在Grid中还是在ScrollView中有问题吗?

这是我的代码:

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++;
        }

这是我的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>

1 个答案:

答案 0 :(得分:1)

设置View

<label for="13"> <input id="13" value="13" type="radio" name="choice">S1&nbsp;&nbsp;&nbsp;S1&nbsp;&nbsp;&nbsp; </label> <label for="14"> <input id="14" value="14" type="radio" name="choice">S11&nbsp;&nbsp;&nbsp;S11&nbsp;&nbsp;&nbsp; </label> <label for="15"> <input id="15" value="15" type="radio" name="choice">S111&nbsp;&nbsp;&nbsp;S111&nbsp;&nbsp;&nbsp; </label> <label for="16"> <input id="16" value="16" type="radio" name="choice">S1111&nbsp;&nbsp;&nbsp;S1111&nbsp;&nbsp;&nbsp; </label> <label for="17"> <input id="17" value="17" type="radio" name="choice">S11111&nbsp;&nbsp;&nbsp;S11111&nbsp;&nbsp;&nbsp; </label> <label for="18"> <input id="18" value="18" type="radio" name="choice">S111111&nbsp;&nbsp;&nbsp;S111111&nbsp;&nbsp;&nbsp; </label> <label for="19"> <input id="19" value="19" type="radio" name="choice">S1111111&nbsp;&nbsp;&nbsp;S1111111&nbsp;&nbsp;&nbsp; </label> <label for="20" class="activelistchoicerow"> <input id="20" value="20" type="radio" name="choice">S11111111&nbsp;&nbsp;&nbsp;S11111111&nbsp;&nbsp;&nbsp; </label>