Xamarin.Forms AbsoluteLayout在iOS设备上的问题(内容不可见)

时间:2019-01-05 18:53:01

标签: c# visual-studio xamarin.forms xamarin.ios

我正在使用Visual Studio for mac 2017运行xamarin以便在IOS设备(Ipad)上进行部署,但是当我在Android上运行相同的代码时,它运行良好(这意味着我可以在android设备上看到内容),但是当我在ios设备上运行该应用程序,此页面未显示任何内容。我正在使用绝对布局的XAML代码,如下所示(我已经在PCL中编写了所有代码,并且在此应用程序中使用了依赖注入方法)

<?xml version="1.0" encoding="utf-8" ?>
<controls:CustomContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:controls="clr-namespace:FormsControls.Base;assembly=FormsControls.Base"
    xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms" 
    xmlns:pages="clr-namespace:FormsApplication.Pages"
    xmlns:animation="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"                        
    xmlns:templates="clr-namespace:FormsApplication.Templates;assembly=FormsApplication"
    xmlns:common="clr-namespace:FormsApplication.Converters;assembly=FormsApplication"
    xmlns:local="clr-namespace:FormsApplication.Helpers;assembly=FormsApplication"                        
    x:Class="FormsApplication.Pages.SelectItemPage" BackgroundColor="#353839"
    PageAnimation="{Binding PageAnimation}" x:Name="ListItemPage">
    <controls:CustomContentPage.Resources>
        <ResourceDictionary>
            <local:ResturentItemToImageSourceConverter x:Key="severityTypeImageConvertertwo"/>
        </ResourceDictionary>
    </controls:CustomContentPage.Resources>
    <controls:CustomContentPage.Behaviors>
        <controls:EventToCommandBehavior EventName="Appearing" Command="{Binding PageAppearingCommand}"/>
        <controls:EventToCommandBehavior EventName="Disappearing" Command="{Binding PageDisappearingCommand}"/>
    </controls:CustomContentPage.Behaviors>
    <AbsoluteLayout>
        <Grid AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" RowSpacing="10" Padding="8,0,8,8">
            <Grid.RowDefinitions >
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>                
            </Grid.RowDefinitions>
            <!--<controls:CustomNavBar ImagePath="{Binding Photo}"  SecondButtonText="Cart" 
                               SecondButtonTapCommand="{Binding ActionCommand}"/>-->

            <controls:CustomNavBar Title="{Binding Title}" ShowBackButton="true" BackgroundColor="#800020">
                <RelativeLayout Style="{StaticResource CustomNavBarStyle}" BackgroundColor="#800020">
                    <ContentView>
                        <controls:CustomNavBar ShowBackButton="true" BackgroundColor="#800020"/>
                        <ContentView.GestureRecognizers>
                            <!--<TapGestureRecognizer/>-->
                            <TapGestureRecognizer Tapped="TapGestureRecognizer_OnTappedtwo"  />
                        </ContentView.GestureRecognizers>
                    </ContentView>
                    <Image Source="DishCartTwo.png" HeightRequest="45" WidthRequest="45" x:Name="yellowBoxView"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.20,Constant=0}"  
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.85,Constant=0}"/>
                    <Image Source="circlexxl.png" IsVisible="{Binding IsImageCircleVisible}" HeightRequest="20" WidthRequest="20" x:Name="redBoxView"
                       RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, Property=Y, ElementName=yellowBoxView, Factor=1,Constant=-5}" 
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, Property=X, ElementName=yellowBoxView, Factor=1,Constant=25}"/>
                    <Label HorizontalTextAlignment="Center"  IsVisible="{Binding IsImageCircleVisible}"  FontSize="14" TextColor="White" HeightRequest="15" WidthRequest="20" Text="{Binding CartItemCount}"
                               x:Name="labelText" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, Property=Y, ElementName=yellowBoxView, Factor=1,Constant=-5}" 
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, Property=X, ElementName=yellowBoxView, Factor=1,Constant=25}"/>
                    <ContentView.GestureRecognizers>
                        <TapGestureRecognizer x:Name="tapcart" Command="{Binding GotToCartCommand}"/>
                    </ContentView.GestureRecognizers>
                </RelativeLayout>
            </controls:CustomNavBar>
            <ListView x:Name="listView" Grid.Row="1" RowHeight="360"
            HasUnevenRows="true" ItemsSource="{Binding FoodItems}"
            SeparatorVisibility="None" CachingStrategy="RecycleElementAndDataTemplate">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Frame CornerRadius="20" Grid.Row="1" Padding="0" BackgroundColor="Transparent" Margin="0,10,0,10">
                                <Grid RowSpacing="0" >                                
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="340" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*"/>                                        
                                    </Grid.RowDefinitions>
                                    <!--<Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>-->
                                 <!--<controls:RoundedBoxView Grid.RowSpan="2" BackgroundColor="Transparent" BorderColor="Black" CornerRadius="20" BorderThickness="50"/>-->
                                    <!--<Frame CornerRadius="10" Grid.RowSpan="2" Padding="0" BackgroundColor="Transparent">-->
                                    <!--<ffimageloading:CachedImage CacheType="None"  FadeAnimationForCachedImages="False"  DownsampleUseDipUnits="True"  DownsampleToViewSize="False" Grid.RowSpan="2" Source="{Binding ImageSource}" Aspect="AspectFill"
                                             CacheDuration="{Binding CacheDuration}"  />-->
                                    <local:CustomCachedImage Grid.RowSpan="2" DownsampleToViewSize="False" Source="{Binding ., Converter={StaticResource severityTypeImageConvertertwo}}" Aspect="AspectFill" DownsampleUseDipUnits="True" FadeAnimationForCachedImages="False" />
                                        <Button  x:Name="cartbutton" Grid.Row="0" Command="{Binding Source={x:Reference ListItemPage}, Path=BindingContext.CartCommand}" 
                                     CommandParameter="{Binding .}" HorizontalOptions="End" VerticalOptions="Start"  Image="{Binding CartImage}" 
                                     BackgroundColor="Transparent" Margin="0,5,5,0" />

                                        <StackLayout Grid.Row="0" HorizontalOptions="Start" Spacing="0" VerticalOptions="Start" Orientation="Vertical"
                                     BackgroundColor="Transparent" Margin="5,5,5,70">
                                            <!--<Button Image="dombaSmall.jpg" BorderColor="Black" BorderWidth="1"                                               
                           VerticalOptions="Start" FontAttributes="Bold" />  -->
                                            <Label Text="More Info" FontSize="25" TextColor="White" 
                                  BackgroundColor="Transparent"  HorizontalOptions="EndAndExpand"              
                           VerticalOptions="Start" FontAttributes="Bold" Margin="10,0,0,0"/>
                                        </StackLayout>
                                        <StackLayout Grid.Row="0" HorizontalOptions="End" Spacing="0" VerticalOptions="End" Orientation="Horizontal"
                                     BackgroundColor="Transparent" Margin="0,5,5,70">
                                            <Button Text="-" BorderColor="White" BorderWidth="1"  FontSize="25" TextColor="White" 
                                  BackgroundColor="Black" Opacity="0.6" Command="{Binding Source={x:Reference ListItemPage}, Path=BindingContext.RemoveQuantity}" 
                                     CommandParameter="{Binding .}" CornerRadius="10" 
                                        HorizontalOptions="EndAndExpand"              
                           VerticalOptions="Start" FontAttributes="Bold" />
                                            <Button Text="{Binding Quantity}" BackgroundColor="Black" BorderWidth="1"
                                            FontSize="25" HorizontalOptions="CenterAndExpand" BorderColor="White" CornerRadius="10"
                                        VerticalOptions="Start" FontAttributes="Bold" Opacity="0.6" TextColor="White"/>
                                            <Button Text="+" BorderColor="White" BorderWidth="1"  FontSize="25" TextColor="White" CornerRadius="10" 
                                      BackgroundColor="Black" Opacity="0.6" Command="{Binding Source={x:Reference ListItemPage}, Path=BindingContext.AddQuantity}" 
                                     CommandParameter="{Binding .}"  
                                        HorizontalOptions="StartAndExpand" 
                           VerticalOptions="Start" FontAttributes="Bold" />
                                        </StackLayout>
                                    <BoxView BackgroundColor="Black" Opacity="0.1" Grid.RowSpan="3" />
                                    <BoxView  Grid.Row="1" Color="#800020" Opacity="0.6"/>
                                    <BoxView  Grid.Row="2" Color="#800020" Opacity="0.6"/>
                                    <Label Grid.Row="1" Text="{Binding Name}" XAlign="Start" TextColor="White" FontSize="25"  VerticalTextAlignment="Center" FontAttributes="Bold" Margin="10,0,0,0">
                                        <Label.FontFamily>
                                            <OnPlatform x:TypeArguments="x:String">
                                                <On Platform="iOS" Value="OpenSans-Semibold"/>
                                                <On Platform="Android" Value="NeutraText_BoldAlt.ttf#NeutraText_BoldAlt.ttf"/>
                                                <On Platform="UWP" Value="Assets\Fonts\OpenSans-Semibold.ttf#Open Sans"/>
                                            </OnPlatform>
                                        </Label.FontFamily>
                                    </Label>
                                    <Label Grid.Row="1" Text="{Binding Price , StringFormat='{}Rs{0:F1}'}" XAlign="End" TextColor="White" FontSize="25"  VerticalTextAlignment="Center" FontAttributes="Bold" Margin="0,0,18,0">
                                        <Label.FontFamily>
                                            <OnPlatform x:TypeArguments="x:String">
                                                <On Platform="iOS" Value="OpenSans-Semibold"/>
                                                <On Platform="Android" Value="NeutraText_BoldAlt.ttf#NeutraText_BoldAlt.ttf"/>
                                                <On Platform="UWP" Value="Assets\Fonts\OpenSans-Semibold.ttf#Open Sans"/>
                                            </OnPlatform>
                                        </Label.FontFamily>
                                    </Label>
                                    <Label Grid.Row="2" Text="{Binding Category}" HorizontalTextAlignment="Start" TextColor="White" FontSize="25"  VerticalOptions="Start" FontAttributes="Italic" Margin="10,0,0,0"/>
                                    <!--</Frame>-->
                                                           <!--<BoxView HeightRequest="5" Grid.Row="2" 
                                     HorizontalOptions="FillAndExpand" BackgroundColor="#353839" VerticalOptions="FillAndExpand"/> -->                              
                             </Grid>                                
                            </Frame>                            
                            <!--<templates:ListItemTemplate ParentContext="{Binding BindingContext, Source={x:Reference ListItemPage}}"/>-->

                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.Behaviors>
                    <controls:EventToCommandBehavior EventName="ItemTapped" Command="{Binding ListItemTappedCommand}" CommandParameter="{x:Reference listView}"/>
                </ListView.Behaviors>
            </ListView>
            <ContentView Grid.Row="1" IsVisible="{Binding IsLoading}" BackgroundColor="#353839">
                <animation:AnimationView x:Name="AnimationViewthre" Animation="Animation/its_lunch_time.json" AutoPlay="true" Loop="True" Margin="100,80,100,80"/>
                <!--<ActivityIndicator IsRunning="{Binding IsLoading}" VerticalOptions="Center" HorizontalOptions="Center" Color="{StaticResource DarkSkyBlue}"/>-->
            </ContentView>
        </Grid>
        <pages:ImageButton Source="ic_home"
                           Command="{Binding GoToHomeCommand}"
                           AbsoluteLayout.LayoutFlags="PositionProportional"
                           AbsoluteLayout.LayoutBounds="1.0,1.0,-1,-1"
                           Margin="15" />
    </AbsoluteLayout>
</controls:CustomContentPage>

我很不熟悉xamarin ios开发帮助,在此先感谢您的支持。

1 个答案:

答案 0 :(得分:0)

我有类似的事情,并注意到当RowDefinitions“ Heights”设置为“ *”时,它们在IOS上的AbsoluteLayout中不能很好地播放。给您的身高一些绝对值,看是否是这种情况。基本上,我认为某些布局容器不会像您期望的那样在IOS中填充和扩展。