【问题标题】:Dealing with iOS and Android diferences on xamarin.forms处理 xamarin.forms 上的 iOS 和 Android 差异
【发布时间】:2019-05-10 16:55:56
【问题描述】:

我正在构建一个跨平台应用程序。我刚刚完成了我的原型,它在 android 上运行良好。然而,我开始在 iOS 上测试原型,我遇到了一些我不知道如何解决的问题,我希望你们能帮助我。

所以,现在我有两个问题: 1st > 在 listview 内的 android 按钮上,正在识别其事件处理程序/命令并触发事件。但在 iPhone 上,它被忽略了。

2nd > iPhone 似乎在我的视图中添加了一些在 android 上没有出现的图标,它们对我没有实用程序。有什么办法可以删除它们吗?

Xaml:

                   <local:CustomListView.ItemTemplate>
                        <DataTemplate>
                            <local:CustomViewCell>
                                <ContentView Padding="10,10,10,0">
                                    <Frame BackgroundColor="{Binding Cor}" CornerRadius="5">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="15"/>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="*"/>
                                            </Grid.RowDefinitions>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="20"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="20"/>
                                            </Grid.ColumnDefinitions>
                                            <Button Grid.Row="0" Grid.Column="2" Image="{Binding ImageSource}" Rotation="90" BackgroundColor="Transparent" HorizontalOptions="EndAndExpand"
                                                         CommandParameter="{Binding .}" Command="{Binding BindingContext.CommandoOpcoes, Source={x:Reference tarefas}}"/>
                                            <Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Scale="0.7" Source="{local:ImageResource x.Images.location1.png}"/>
                                            <Label Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2" Text="{Binding Titulo}" FontAttributes="Bold" FontSize="Medium" VerticalTextAlignment="Center"/>
                                            <Image Grid.Row="2" Grid.Column="0" Scale="0.7" Source="{local:ImageResource x.Images.clock.png}"/>
                                            <Label Text="{Binding Duracao}" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" VerticalTextAlignment="Center"/>
                                            <Image Grid.Row="3" Grid.Column="0" Scale="0.7" Source="{local:ImageResource x.Images.location2.png}"/>
                                            <Label Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding ObjectivoAno}" VerticalTextAlignment="Center"/>
                                        </Grid>
                                    </Frame>
                                </ContentView>


查看模型:


        public Command CommandoOpcoes
        {
            get;
            private set;
        }

        /*
            * Menu de um item da lista clicado
            * Apresenta opções de editar, apagar e marcar uma tarefa como concluída
        */
        private void MostraOpcoes(object t)
        {
            var Tarefa = t as Tarefa;

            async void apagarTarefa()
            {
                var res = await App.Current?.MainPage?.DisplayAlert(AppResource.Confirmacao, AppResource.Apagar, AppResource.Nao, AppResource.Sim);

                if (res == false)
                {
                    Tarefas.Remove(Tarefa);
                    NTarefas--;
                }
            }

            async void editarTarefa()
            {
                var page = new EditarTarefa()
                {
                    BindingContext = Tarefa
                };
                if (PopupNavigation.Instance.PopupStack.Count > 0)
                    await PopupNavigation.Instance.PopAllAsync(false);
                await PopupNavigation.Instance.PushAsync(page, true);
            }

            void completarTarefa()
            {
                if (Tarefa.Cumprido == false)
                {
                    Tarefa.Cumprido = true;
                    Tarefa.Cor = Color.FromHex("#E5F2E5");
                    NTarefasConcluidos++;
                    if (NTarefasNaoConcluidos > 0)
                        NTarefasNaoConcluidos--;
                }
                else
                {
                    Tarefa.Cumprido = false;
                    Tarefa.Cor = Color.FromHex("#FFE5E5");
                    NTarefasNaoConcluidos++;
                    if (NTarefasConcluidos > 0)
                        NTarefasConcluidos--;
                }
            }

            ActionSheetConfig config = new ActionSheetConfig();



            if (Tarefa.Cumprido)
                config.Add(AppResource.nCompleto, completarTarefa, "completo.png");
            else
            {
                config.Add(AppResource.EditarTarefa, editarTarefa, "edit.png");
                config.Add(AppResource.Completo, completarTarefa, "completo.png");
            }

            config.SetDestructive(AppResource.ApagarTarefa, apagarTarefa, "delete.png");

            config.UseBottomSheet = true;
            UserDialogs.Instance.ActionSheet(config).Dispose();
            UserDialogs.Instance.ActionSheet(config);
        }

        public TarefasViewModel()
        {
            Tarefas = new ObservableCollection<Tarefa>(App.tarefas.Where(x => x.Data == DateTime.Today).ToList());
            NTarefas = Tarefas.Count;
            NTarefasConcluidos = Tarefas.Where(x => x.Cumprido == true).Count();
            NTarefasNaoConcluidos = Tarefas.Where(x => x.Cumprido == false).Count();
            CommandoOpcoes = new Command(q => MostraOpcoes(q));
        }

iOS 上带有不需要的图标的视图图像: https://imgur.com/VTXRXNh

Android 上的图像: https://imgur.com/v6dfkEW

【问题讨论】:

  • iOS 中的额外箭头是 DisclosureIndicator。请参阅此docs.microsoft.com/en-us/xamarin/ios/user-interface/controls/…。为了更好的解释
  • 可能你必须在你的 CustomListView 中做一些改变
  • 您是否为 iOS 上的列表视图定义了自定义渲染器?列表视图的默认外观不包含视图单元右侧的披露指示符。也许是那个附件禁用了您的按钮命令。您能否分享一个示例,以便我们帮助您调查您的问题?
  • 自定义列表视图的示例? @LandLu-MSFT 你是指代码还是图像?
  • @Kelve 是的,您的列表视图示例可以重现您的问题。

标签: android ios xaml xamarin xamarin.forms


【解决方案1】:

所以,我找到了解决方案。这很简单。在 ViewCell 上,StyleId 属性可以将显示按钮添加到 iOS 列表中。 为了没有这些披露按钮,我刚刚做了:

<ViewCell StyeleId="none">...</ViewCell>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-12
    • 2017-11-24
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    相关资源
    最近更新 更多