【问题标题】:GestureRecognizer doesn't work only in ios xamarin.formsGestureRecognizer 仅在 ios xamarin.forms 中不起作用
【发布时间】:2018-03-05 06:25:11
【问题描述】:

我正在使用 xamarin.forms 做一个应用程序,但是, 出于某种原因,在更改此页面后,我将图像放大并添加了一些网格,手势识别器仅在 iphone 中停止工作,在 android 中正常工作......有人看到这段代码中的问题了吗?因为,到目前为止,我做不到。 由于需要模板,我正在以编程方式创建页面。

private void CriaTela()
    {
        int row = 0;
        int column = 0;

        gridtextura.RowSpacing = 5;
        gridtextura.ColumnSpacing = 15;

        lstCategorias = lstCategorias.OrderBy(o => o.nome).ToList();

        foreach (var item in lstCategorias)
        {
            Grid GridContent = new Grid
            {
                RowSpacing = 0,
                //BackgroundColor = Color.Pink,
                VerticalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions =
            {
                new RowDefinition { Height = new GridLength(8, GridUnitType.Star) },
                new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
            }
            };

            var textura = new CachedImage();
            textura.Source = "texturaCateg";
            textura.HorizontalOptions = LayoutOptions.FillAndExpand;
            textura.VerticalOptions = LayoutOptions.FillAndExpand;
            textura.Aspect = Aspect.Fill;

            GridContent.BindingContext = item;

            Grid boxColorView = new Grid
            {
                RowSpacing = 0,
              //  BackgroundColor = Color.Pink,
                VerticalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions =
            {
                new RowDefinition { Height = new GridLength(2, GridUnitType.Star) },
                new RowDefinition { Height = new GridLength(8, GridUnitType.Star) }
            }
            };

            boxColorView.Children.Add(new BoxView { Color = Color.FromHex(item.corFundo), VerticalOptions = LayoutOptions.FillAndExpand }, 0, 1 );
            boxColorView.Children.Add(textura, 0, 1);

            boxColorView.Children.Add(new BoxView { VerticalOptions = LayoutOptions.FillAndExpand }, 0, 0);
            gridtextura.Children.Add(boxColorView, column, row);
            gridtextura.Children.Add(GridContent, column, row);

            //Qual categoria foi escolhida?
            var CliqueCategoria = new TapGestureRecognizer();

            CliqueCategoria.Tapped += (s, e) =>
            {
                CriaLoading();
                var stacklayout = s as Grid;
                categoriaEscolhida = (Categorias)stacklayout.BindingContext;
                ChamaProdutos();
            };

            GridContent.GestureRecognizers.Add(CliqueCategoria);
            GridContent.BackgroundColor = Color.Green;
            if (item.imagem != null && item.imagem != "")
            {
                int initIndex = item.imagem.IndexOf(',');
                string image = "";

                image = item.imagem.Substring(initIndex + 1);

                try
                {
                    GridContent.Children.Add(new CachedImage { Source = ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(image))), VerticalOptions = LayoutOptions.FillAndExpand }, 0, 0);
                }
                catch (Exception e)
                {
                    GridContent.Children.Add(new CachedImage { Source = "error.png", VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.Fill, HeightRequest = 50, WidthRequest = 50 }, 0, 0);

                }
            }

            GridContent.Children.Add(new Label { Text = item.nome, TextColor = Color.FromHex(item.corTexto), FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)), FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.CenterAndExpand }, 0, 1 );

            if (column == 0)
            {
                column = 1;
            }
            else
            {
                column = 0;
                row++;
            }

        }

    }

----------------编辑-------------------

我对这个问题了解得更多...因为现在我有一个按钮图像...并且它正在工作...但是现在,它超过了其他图像,然后它不再工作了.. .但它在另一张图片上...与我在此处发布的此代码的情况相同...我有一个网格超过其他...在相同的位置、宽度和长度...并且顶部网格没有收到水龙头

【问题讨论】:

  • 有可能某些子元素正在捕获点击而不让它们通过父网格。尝试在GridContent 子控件上设置InputTranparent = true
  • 更多细节在这里:developer.xamarin.com/api/property/…
  • 所有孩子都应该收到 InputTranparent = true,对吧?
  • 我对这个问题了解得更多...因为现在我是一个按钮的图像...并且它正在工作...但是现在,它超过了其他图像,然后它不再工作了...但它结束了...这是我在此处发布的代码的相同情况...我有一个网格超过其他...在相同的位置和宽度,长度...并且顶部网格没有收到水龙头
  • 尝试绝对布局而不是网格。或者你可以关注这个forums.xamarin.com/discussion/61925/…

标签: c# xamarin mobile layout xamarin.forms


【解决方案1】:

问题出在 xaml...主网格在另一个网格内...这个另一个网格造成了问题...我想可能是点击次数过多

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2019-02-27
    • 2020-10-24
    • 1970-01-01
    相关资源
    最近更新 更多